views:

49

answers:

3

How do I make a remote POST request with custom parameters with a link_to helper in rails 3?

I tried something like this:

link_to 'Submit', model_path, :query => "value", :remote => true, :method => :post

The POST works and the control comes to the action in the controller, but I don't get the POST parameters in params or anywhere else.

How do I do this?

A: 

Did you see this?

http://stackoverflow.com/questions/3486018/making-post-request-in-rails-with-hyperlinks

Trip
In fact, it was I who asked that question too :PThough the title is same, the problem is slightly different.
manu1001
haha, i can't believe i didn't notice that. glad everything worked out though.
Trip
A: 

You need made 2 things

  1. Call the csrf_meta_tag helper in your head of HTML
  2. Add the rails.js for your javascript library. Prototype or jQuery.
shingara
A: 

Well, I got it. I need to pass parameters to the model_path function itself like,

 model_path(:query => "value")

Didn't realize it was a function all along. Paradigm change...

manu1001