ryanb / nested_form

Rails plugin to conveniently handle multiple models in a single form.
MIT License
1.79k stars 505 forks source link

Does this gem works with rails 4? #295

Closed andrewvmail closed 10 years ago

andrewvmail commented 10 years ago

Does this gem works with rails 4 if so what is required? From the wiki I can only see instructions for rails 3 and can't find any info from the issues.

Thanks !

lest commented 10 years ago

There is no big differences between rails 3 and rails 4. Have you tried it with rails 4 and something doesn't work?

andrewvmail commented 10 years ago

I'm such a noob I forgot to define some routes. I can confirm that this Gem works for Rails 4.

TheNotary commented 9 years ago

I was having trouble... I think rails 4 defaults to checking the params in the controller rather than in the model, so the controller should be changed in addition to the other things, and the model shouldn't have attr_accesible, or attr_accessor set for the attributes.

# users controller
def user_params
  params.require(:user).permit(:first_name, :last_name, :email, :password, :password_confirmation, :authorization).tap do |whitelisted|
    whitelisted[:problems_attributes] = params[:user][:problems_attributes] unless params[:user][:problems_attributes].nil?
  end      
end

The gem otherwise works identically.