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

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -