0

在我尝试更新我的绘画模型后,我得到了上述标题错误。

这是我的绘画控制器

def update 
    @painting = Painting.find(params[:id])
    if @painting.update_attributes(params[:painting])
        redirect_to :action => 'show', :id => @painting
    else
        @paintings = Painting.find(:all)
        render :action => 'edit'
    end
end

这是我的模型

class Painting < ActiveRecord::Base
    attr_accessible :gallery_id, :name, :image, :avatar
    belongs_to :gallery
    mount_uploader :avatar, ImageUploader
    has_attached_file :avatar, :default_url =>     "/images/:style/missing.png"
      # , :url  => "/assets/:id/:style/:basename.:extension", :path => ":rails_root/public/assets/:id/:style/:basename.:extension"
    validates_presence_of :name

end

这是我的绘画形式部分

<%= form_for([@gallery,@painting], :html => {:multipart => true}) do |f| %>
    <!-- <#%= form_for @painting, :html => {:multipart => true} do |f| %> -->

      <p>
        <%= f.label :name %><br />
        <%= f.text_field :name %>
      </p>
      <p><%= f.file_field :avatar %></p>

      <p><%= f.submit %></p>
    <% end %>

一幅画属于一个画廊,即画廊包含绘画。PS我也在使用carrierwave。

4

1 回答 1

0

好的,这是 mountuploader 的问题。我不得不把它注释掉,它起作用了.Phew :-)

class Painting < ActiveRecord::Base
    attr_accessible :gallery_id, :name, :image, :avatar
    belongs_to :gallery
    # mount_uploader :avatar, ImageUploader
    has_attached_file :avatar, :default_url => "/images/:style/missing.png", :url  => "/assets/:id/:style/:basename.:extension", :path => ":rails_root/public/assets/:id/:style/:basename.:extension"
    validates_presence_of :name
    # skip_callback :save, :after, :remove_previously_stored_avatar

end
于 2013-11-15T04:44:59.943 回答