Calling a controller's action without a named route in Rails 3
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
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
精彩评论