I used Polymorphic Association Post model: has_many :images, :as => :imageable Image model: belongs_to :imageable, :polymorphic => true
The bottom of the post form, I created an image upload开发者_如何学JAVA form. When the user upload the picture, the ajax redirect to form page. There is the problem. I use this code:
def create
return unless request.xhr?
@imageable = find_imageable
@image = @imageable.images.build(params[:imageable])
@image.save
render :layout => false
end
After submit the form, I redirected to post/:id/images page, whats wrong?
The form:<%= form_tag admin_static_images_path(@static), :remote => true, :multipart => true do %>
<%= file_field :imageable, :photo %>
<% end %>
加载中,请稍侯......
精彩评论