生产模式中的Rails 3.1和Paperclip无法解释的路径问题

时间:2011-09-15 15:53:20

标签: ruby-on-rails ruby-on-rails-3 paperclip ruby-on-rails-3.1

请帮助,我不知道该怎么办......

在我的机器上一切正常。但是在点击提交时的生产盒上,有些东西正在切割。

正确设置环境中回形针的命令路径。

这是我在提交上传表单时在production.log中获得的内容:

 Started POST "/app_medias/1/media_image"
 ActionController::RoutingError (No route matches [POST] "/1/media_image"):

/ app_medias /离开路线wtf ???

的Gemfile

gem 'paperclip', :git => "http://github.com/thoughtbot/paperclip.git"

路线:

  resources :app_medias do 
    member do
      post 'media_image' #upload action
    end
  end

佣金路线:

media_image_app_media POST |  /app_medias/:id/media_image(.:format)  |  {:controller=>"app_medias", :action=>"media_image"}

控制器:

  def show
    @media = AppMedia.find(params[:id])
    @media_image = @media.media_images.build
  end

  def media_image
    @media = AppMedia.find(params[:id])
    @media_image = @media.media_images.build(params[:media_image])
    if @media_image.save
      flash[:notice] = "Saved"
      redirect_to app_media_path(@media)
    else
      flash[:error] = "Error"
      render :action => 'show'
    end
  end

模型

  has_attached_file :media_image,
                    :styles => {
                          :thumb => "50x50#",
                          :small  => "x110",
                          :original => "x600" } , 
                          :url => ("/assets/_media/:attachment/:id_:style_:basename.:extension").downcase,
                          :path => (":rails_root/public/assets/_media/:attachment/:id_:style_:basename.:extension").downcase

查看:

<%= form_for :media_image, :as => @media_image, :url => {:action => "media_image"}, :html => {:multipart => true} do |f| %>
    <%= f.file_field :media_image %><%= f.submit 'Upload', :disable_with => 'uploading...', :class => 'button primary' %>
<%- end -%>

我也试过form_for @media_image,:url =&gt; {:action =&gt; “media_image} ... localy可以使用,而不是在制作中。

有人可以帮忙吗?我被卡住了......

谢谢

1 个答案:

答案 0 :(得分:1)

解决! ModSecurity 是问题所在。现在已关闭,上传工作正常。