Topic: Need help updating db attributes through nested route

Hi all. Let me preface this by saying, i'm pretty new to rails and programming.

I'm trying to make some links to toggle a boolean attribute on and off. I've essentially succeeded in doing it on a non-nested resource by doing the following:

Route:   resources :my_resource do
             get 'toggle_attribute', :on => :member
             end

Controller:  def toggle_attribute
                 @resource = Resource.find(params[:id])
                 @resource.toggle!(:attribute)
                 end

View: <%= link_to "Toggle Resource", toggle_attribute_resource_path(@resource), :remote => true %>

First, like I said above, this works on my non-nested route, however no matter what solution I try to add to the controller I can't get my link to flash a message or re-direct to anything when clicked, you click the button and nothing happens, you have to manually refresh to see the change.

Second, I can't figure out how to get this same sort of thing to work on a route that is nested like so:

Route:  resources :resource_1 do
              resources :resource_2
            end

Can anyone give me some tips?

Thanks a ton in advance. This stuff has been driving me batty.

Last edited by xilch (2012-11-08 12:14:28)