Haseeb Ahmad
Haseeb Ahmad

Reputation: 8730

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?

Upvotes: 1

Views: 167

Answers (1)

Ganesh Kunwar
Ganesh Kunwar

Reputation: 2653

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.

Upvotes: 1

Related Questions