I am trying to reproduce railscast #196 in Rails 4. However, I\'m experiencing some problems.
In my example I try to generate a Phonebook - each Person could have mu
In order to get three phones in the view change form_for :person
to form_for @person
(you want to use the object you've built here) as follows:
<%= form_for @person, url: people_path do |f| %>
This should fix the ForbiddenAttributes
error as well.
And your create
action could be:
def create
@person = Person.create(person_params)
redirect_to people_path
end
Update:
<%= form_for :person do |f| %>
creates a generic form for the Person
model and is not aware of the additional details you apply to a specific object (in this case @person
in your new
action). You've attached three phones
to the @person
object, and @person
is not the same as :person
which is why you didn't see three phone fields in your view. Please reference: http://apidock.com/rails/ActionView/Helpers/FormHelper/form_for for further details.