views:

328

answers:

2

how to call a different controller's action using link_to_remote

:url => {:controller => "Posts", :action => "update"} doesn't work

+1  A: 

the method:
link_to_remote(name, options = {}, html_options = nil)

passing in a hash like:
link_to_remote "hug kittens", { :url => { :controller => 'kittens', :action => 'show' } }

as the second argument (options) works. verified.

the result:
<a onclick="new Ajax.Request('/kittens/hug', {asynchronous:true, evalScripts:true, parameters:'authenticity_token=' + encodeURIComponent('/BdZwHdC/QqtBJsdCU+cCHxabHj/QHUT6i8ggbr5CtY=')}); return false;" href="#">hug kittens</a>

the problem with your implementation might be, that there is no "real" update-url (except you created one by hand). please have a look at the url of your edit-form. it's actually a post-request to "posts/:post_id".

rubiii
Thank you, that works
A: 

<%= link_to_remote "Save", :url=>{:controller => "Posts", :action => "update"}, :update=>"div_id" %>

manish nautiyal