Answer the question
In order to leave comments, you need to log in
How to make the form see comments?
I can't even really compose a question for a google search. I know there should be a thread like this but I can't find it to watch.
Basically I have: Controller: Posts
Models: Post , Comment
The Post model has a one-to-many relationship with the Comment
model
Example:
class Post < ActiveRecord::Base
has_many :comments
end
class Comment < ActiveRecord::Base
belongs_to :post
end
class CreateComments < ActiveRecord::Migration
def change
create_table :comments do |t|
t.integer :user_id
t.text :text
t.timestamps
end
end
end
<%= @post.name %>
<%= form_for @comments do |f| %>
<%= f.text_field :text %>
<% end %>
undefined method `model_name' for Comment::ActiveRecord_Relation:Class
Answer the question
In order to leave comments, you need to log in
Hope this helps
Read more here
rusrails.ru/rails-form-helpers#sozdanie-slozhnyh-form
class Person < ActiveRecord::Base
has_many :addresses
accepts_nested_attributes_for :addresses
end
class Address < ActiveRecord::Base
belongs_to :person
end
<%= form_for @person do |f| %>
Addresses:
<ul>
<%= f.fields_for :addresses do |addresses_form| %>
<li>
<%= addresses_form.label :kind %>
<%= addresses_form.text_field :kind %>
<%= addresses_form.label :street %>
<%= addresses_form.text_field :street %>
...
</li>
<% end %>
</ul>
<% end %>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question