Home > Ruby on Rails > Setting method parameter in form_remote_tag in RESTful setup

Setting method parameter in form_remote_tag in RESTful setup

By now, I gotten used to reading the codes if the Rails api documentation is not clear enough.

If you are using Rails in a RESTful setup, and using form_remote_tag, or any other methods that generate a AJAX request, then you might encounter this problem.  RESTful requires you to understand that to get a listing of information, you’ll need to use a HTTP GET method.   If you do not specify the method during the form_remote_tag call, the default HTTP method is POST.  So when the AJAX request is called, the Rails engine will interpret it to be a “Create” call, and the “create” method in your controller is used.

You will get a nasty mess…

Actually the way to set the method in your AJAX request is quite simple.  Just include :method => ‘get’ in your options hash.  For example:

form_remote_tag :url => {:action => “index”}, :html => {:id => “people_filter_form”}, :method => ‘get’

My problem was to put it in the :url hash, or :html hash.  Won’t work. 🙂

Categories: Ruby on Rails
  1. ego
    August 21, 2007 at 9:57 pm

    thks – it works

  2. Eduardo Reche Lopes
    May 15, 2008 at 3:36 am

    Thank you man! I’ve trying something like this:

    form_remote_tag :url => {:action => “index”}, :html => { :method => ‘get’ }

    … and not working!

  3. s
    July 6, 2008 at 2:37 am


  4. aris
    July 6, 2008 at 4:19 am

    help me…
    form_remote_tag :url => {:action => “index”}, :html => { :method => ‘get’ }

    … and not working too…


  5. aris
    July 6, 2008 at 4:21 am

    i meant this:

    form_remote_tag :url => {:action => “index”}, :html => {:id => “people_filter_form”}, :method => ‘get’

    doesnt work too..

    im using rails 2.0.2, btw

  6. davish
    October 16, 2008 at 8:37 pm

    please help me

    form_remote_tag is working as desired in IE but is not working in firefox

    Thanks & regards

    Davish Bhardwaj

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: