accepts_nested_attributes_for + paperclip + polymorphic + problem

Hello Friends,

I am not able to retrieve the value form page

controller
offices_controller
def new
@office = Office.new
end

def create
 @office = Office.new(params[:office])
 @office.save

end
end

VIEW
<% form_for @office do |f| %>
<%= f.text_area :office_name %>
<% f.fields_for :images_attributes do |i| %>
<%= i.file_field :avatar %>
<%end%>
<%= f.submit “Submit” %>
<%end%>

Model

Office.rb
accepts_nested_attributes_for :image

Image.rb
belongs_to :imagable, :polymorphic => true

PROBLEM
When I press submit, the params[:office] only contain :office_name and avatar is getting lost? I don;t know where excatly I am getting wrong.

Thanks for any suggestion

Abhis

Hi Ab,

The form view should read:

<% form_for @office, :html => {:multipart => true} do |f| %>

This is always the case when dealing with file uploads.

antony thanks. It worked,.

Thanks, it worked for me to :smiley: