开发者

request.xhr with different controller

开发者 https://www.devze.com 2023-03-23 11:45 出处:网络
I used Polymorphic Association Post model: has_many :images, :as => :imageable Image model: belongs_to :imageable, :polymorphic => true

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 %>
0

精彩评论

暂无评论...
验证码 换一张
取 消