rails controller action AND javascript onclick

1k views Asked by At

I am trying to do both: call a controller action and react to onclick with a javascript function. At the moment, I only can do one thing. Trying with

<%= button_to 'Call Action', contoller_action_path, :remote => true,
              :method => 'post',
              :onclick => "setSomeJsState('Run'); return(false);" %>

it triggers only the onclick part. Any ideas? Thanks in advance, devyn

1

There are 1 answers

0
Vasfed On BEST ANSWER

return false in js event disables event propagation, and thus rails ujs code to handle button does not run.

Other option is to make an $.ajax call to the action in setSomeJsState function.