ruby-on-railsbutton-to

rails controller action AND javascript onclick


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


Solution

  • 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.