Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails best_in_place gem with nested resource

Does anyone know if it is possible (and, if so, what the syntax is) for using a nested resource with the best_in_place gem?

My routes.rb looks something like this

resources :users do
  resources :goals 
end

I would like to edit the :description field of the goal, but the code in my view for

<%= best_in_place [@user, @goal], :description %>

gives a NoMethodError saying

undefined method `description' for #<Array:0x20e0d28> 

Using

<%= best_in_place @goal, :description %>

give me an undefined method error also because there is no goal_path

I can get the gem to work for @user (the non nested resource) field without problems.

I'm running Rails 3.1.1, Ruby 1.9.2, best_in_place 1.0.4

like image 827
bknoles Avatar asked Jan 08 '12 17:01

bknoles


3 Answers

I figured it out.

I needed to set the path option in the call like so

<%= best_in_place @goal, :description, :path => user_goal_path %>

It works like a champ now!

like image 105
bknoles Avatar answered Jan 05 '23 05:01

bknoles


Add path and the objects to the path:

<%= best_in_place @goal, :description, :path => user_goal_path(@user,@goal) %> 

Somehow the simple path solution of bknoles didn't work for me.

like image 30
VintageOnRails Avatar answered Jan 05 '23 06:01

VintageOnRails


Now above method is deprecated.

According to latest Documentation use ":url" instead of ":path" like below in the example

<%= best_in_place @goal, :description, :url => user_goal_path %>

Cheers!

like image 29
rakesh kumar Avatar answered Jan 05 '23 06:01

rakesh kumar