: onclick does not work in button_to

im trying to call a function using the onclick method of a button. here is the code:

<%= button_to "Close" , :onclick => "show_back(), return false" %> 

but this will not work, every time I click the error occours button

"No action responded to 29. Actions: check, create, delete, edit, search_picture, index, new, save_show, display and update"

be that as it may, when I implement the same in href, it works

  <a onclick="show_back();return false;" href="#."> Close </a> 

can someone tell me what i am doing wrong, thanks in advance.

+4
source share
4 answers

Try this tip

+4
source

you can try this

 =link_to "value", "javascript:function()" 

and add your class if you use as bootstrap, you can try:

 =link_to "value", "javascript:function()", class: 'btn btn-default' 
+3
source

I was looking for something similar. My problem was that I wanted to run the addCookie () function when the user logged in.

Did this with:

 <%= submit_tag 'Go', class: "ses_submit_btn", :onclick => "addCookie()" %> 
+1
source

It worked for me. the key understood that it should be a hash of html_options

 <%= button_to "Click", designer_path(@current_user), { :onclick => "debugger", :class=>"button", :method => :put } %> 
-1
source

Source: https://habr.com/ru/post/1345320/


All Articles