[rails 3] how to write an Ajax call w the new unobtrusive js ?

I have current a js function call I would like to transform into an Ajax request

  = check_box_tag "selection", "1", false, {:id => user.id, :onclick => "showHideMenuItem(this);"}

I found a lot of examples on link_to , but none on a checkbox .. I know I have to add :remote => true somewhere, but that's all I know ..

please, any help or tip will be welcome !

thanks a lot for your links...

erwin

The rails.js UJS file appears to handle only links/anchors or forms.

I went through a "I want to do this with UJS" about a week ago. While I got it to work, I am not sure what I accomplished since I was not doing AJAX - I just wanted to replace a non-working client-side Javascript validation routine.

My journey is detailed in a post: <http://groups.google.com/group/ rubyonrails-talk/browse_thread/thread/0e4cf37dbfab4d94?hl=en#>

I've had limited response on rails3 questions since probably less that 10% of those on the list are currently trying it. I did do some experimenting with what I think you are trying to do. One approach is to wrap your checkbox in a link:

        <%=link_to( check_box_tag( "selection", "1", false, {:id => user.id}) , "/yoururl/1", :remote => true) %> One

In tracing the javascript it will do a GET request to /yoururl/1

if you do:

        <%=link_to( check_box_tag( "selection", "1", false, {:id => user.id}), "/yoururl/1", :remote => true, :"data-method" => "showHideMenuItem") %> One

That will try a POST request to /yoururl/1

If you do "

        <%=link_to( check_box_tag( "selection", "1", false, {:id => user.id}), "/yoururl/1" :"data-method" => "showHideMenuItem") %> One

That will act like the delete action and build a form and submit try to submit it.

Somewhere in there you have to deal with the checkbox. I've never experimented with a xxx.js.erb file, so I guess you do it there.

Hope this gives you a start.

Well, why not try observe_field? like this i did

<%= check_box :campaign, :use_global, {}, 1,0 %> <%= observe_field :campaign_use_global, :url => {:controller => “metakeys”,:action => ‘update_metakeys_flag’, :id => parent_id, :type => “campaign”}, :with => “‘val=’+value”, :method => :post %>

Thanks

the remote_function is still alive ..... I finally ended using it, and it works but the Rails 3 doc is not yet very clear about all this remote stuff....