Rails 4, Paperclip and polymorphic association -


i have 2 models: news , uploadedfile

class news < activerecord::base     has_many :uploadedfiles, as: :parent     attr_accessible :title, :content, :author end  class uploadedfile < activerecord::base     belongs_to :parent, polymorphic: true     has_attached_file :url     attr_accessible :url_file_name, :url_content_type, :url_file_size, :url_updated_at end 

and form:

<%= form_for(@news) |f| %>      <div class="field">          <%= f.fields_for :uploadedfile, f.uploadedfile.new |uf| %>             <%= uf.label :url %><br>             <%= uf.file_field :url %>         <% end %>      </div>    <div class="actions">     <%= f.submit %>   </div> <% end %> 

when i'm submitting form, table uploadedfile not changed

where problem? thank you!

i think have nested arribute :uploadedfiles

class news < activerecord::base      has_many :uploadedfiles, as: :parent     attr_accessible :title, :content, :author, :uploadedfiles_attributes     accept_nested_attributes_for :uploadedfiles end 

and in form : change:

 <%= f.fields_for :uploadedfile, f.uploadedfile.new |uf| %> 

to:

<%= f.fields_for :uploadedfiles, uploadedfile.new |uf| %> 

Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -