ruby - Rails forms - Submitting to subclasses -
new rails, apologize if answer obvious. if have 2 models, user , comments, (1 : n) relationship. when create user creating comment.
the trouble having how write form, or inherent in user class comment associated user?
<%= form_for(@user) |f| %> <%= f.text_field :name %> <%= f.text_area :comment ???? %> <%= f.submit %> <% end %>
i suppose have model comments so....
add in user.rb
has_many :comments accepts_nested_attributes_for :comments
and in controller?
def new @user = user.new @user.comments.build end
and in form view:
<%= form_for @user |f| %> <%= f.text_field :name %> <%= f.fields_for :comments |comment_form| %> <%= comment_form.text_field :description %> <% end %> <% end %>
Comments
Post a Comment