Search code examples
ruby-on-railsrubybest-in-place

How to use Best in place with nested association in ruby on rails


app/models/user.rb

has_one :user_detail

app/models/user_detail.rb

belongs_to :user

unit_number is attribute of user_detail.

I want to edit inline this attribute in user show page.But I can't understand how I do it.

<%= best_in_place user, :unit_number %>

It gives an error.How I do it?


Solution

  • Please try this:

    <%= best_in_place user.user_detail, :unit_number, path: user_detail_path %>
    

    Where user_detail_path is the update user detail path. You have to define this routes from routes.rb.