views:

15

answers:

1

In Rails 3, is there a way to link to a controller's action using ajax without having a named route?

I tried <%= link_to 'Reload', '#', url_for(:action => :reload, :id => @user.id), :remote => true, :method => 'post' %>

but it returns with the error No route matches {:controller=>"users", :id=>2, :action=>"reload"}

My main concern is that I don't want the action to be called by someone typing in a route in the address bar. Is there another way to go about this?

Thanks!

Tim

A: 

if your User resource is in your routes.rb file then you need to add a route to the 7 restful actions.

  resources :user, :member => {:reload => :get}

That will give you the route to work with

   <%= link_to "Reload", user_reload_path(current_user)%>

and that should work for reloading your user object

 rake routes

that will show you all your routes you can work with

Sam