Answer the question
In order to leave comments, you need to log in
Is it possible to add data to a table with a belongs_to relationship?
Is it possible to do this at all? and how to do it? )
Let's say there are posts and comments
Post.rb has_many "comments
Comment.rb belongs_to :post
and a form
<%= form_for([@post, @article.comments.build]) do |f| %>
<p>
<%= f.label :commenter %><br>
<%= f.text_field :commenter %>
</p>
<p>
<%= f.label :body %><br>
<%= f.text_area :body %>
</p>
f.fields_for :post do |f| %>
<%= f.text_field :body2 %>
<% end %>
<p>
<%= f.submit %>
</p>
<% end %>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question