views:

380

answers:

2

what is the proper incantation to make this actually post asynchronously?

form_tag :controller => :magic, :action => :search, :method => post, :remote => true do

method=post and remote=true just get squashed on the end of the url instead of actually making it an ajax post.

A: 

I believe you need to use form_remote_tag instead:

form_remote_tag(:url => { :controller => :magic, :action => :search }) do

The default http method is post.

If you do want to pass extra parameters on a form_tag you need to make them into a separate hash from the url parameters, like this:

form_tag { :controller => :magic, :action => :search }, { :method => post, :remote => true } do
Shadwell
The correct answer is to separate the two hash parameters, but in Rails 3 works with `form_tag` and the `:remote => true` parameter. Rails 3 aims to be unobtrusive with the javascript generated, and the logic for sending it as ajax request lies now in the client side, with the Javascript driver of your choice. See http://railscasts.com/episodes/205-unobtrusive-javascript
Chubas
+3  A: 

The only way I found to do it is to wrap the url parameters in the url_for method.

form_tag url_for(:action => :create, :id => @artist.id), :remote => true do 

However, if you need to the pass the method parameter you might need to wrap that and the remote in parentheses.

Sean