user183167
user183167

Reputation:

rails how to call another controller in link_to_remote

how to call a different controller's action using link_to_remote

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

Upvotes: 0

Views: 1076

Answers (2)

manish nautiyal
manish nautiyal

Reputation: 1

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

Upvotes: 0

rubiii
rubiii

Reputation: 1924

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".

Upvotes: 1

Related Questions