Topic: check_box_tag call action on change

Hi all,
I'm developing an application with Rails 3.0.9 and I have a checkbox and I want to call a function when it is checked/uchecked.
I'm trying with:

<%= check_box_tag "mylabel" t.to_s, false, { :onclick => remote_function( :url => { :action => 'update_preview', :id => t.to_s })} %>      

in the "show" view and this in the controller

  def update_preview
    puts "-> hey!!!"
  end

But the update_preview isn't called
Someone can help me to understand?

Thanks

Re: check_box_tag call action on change

use onchange for a check_box,  NOT onclick

Joe got a job, on the day shift, at the Utility Muffin Research Kitchen, arrogantly twisting the sterile canvas snout of a fully charged icing anointment utensil.

Re: check_box_tag call action on change

I tryed :onchange also (the right event), but it is the same, the function isn't fired

Last edited by nimbuz77 (2011-10-17 15:47:49)

Re: check_box_tag call action on change

What is ending up in log/development.log ?

First,  change puts to

logger.debug("Hey!")

Then run again and look at the log,

you should either see a route error, or Hey!

Joe got a job, on the day shift, at the Utility Muffin Research Kitchen, arrogantly twisting the sterile canvas snout of a fully charged icing anointment utensil.

Re: check_box_tag call action on change

Ok, I did it but nothing is shown in the log file, just the page loading:

Started GET "/showcases/new?mode=dynamic" for 127.0.0.1 at Wed Oct 19 09:08:12 +0200 2011
  Processing by ShowcasesController#new as HTML
  Parameters: {"mode"=>"dynamic"}
Rendered showcases/_form.html.erb (1.3ms)
Rendered showcases/new.html.erb within layouts/application (13.6ms)
Completed 200 OK in 23ms (Views: 19.8ms | ActiveRecord: 0.0ms)

Re: check_box_tag call action on change

Hold on,  remote_function has been removed from rails 3!

http://efreedom.com/Question/1-3332474/ … e-Function

Joe got a job, on the day shift, at the Utility Muffin Research Kitchen, arrogantly twisting the sterile canvas snout of a fully charged icing anointment utensil.

Re: check_box_tag call action on change

Thank you, it pointed me in the right direction.