开发者

:onclick doesn't work in button_to

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

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

but it doesn't work, everytime i click the button an error occours

" No action responded to 29. Actions: checkout, create, destroy, edit, find_c开发者_开发问答art, index, new, save_order, show, and update "

how ever when i impliment the same thing in a href it works

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

can anyone plz tell me what im doing wrong, thanks in advance..


you can try this

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

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

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


I was looking for something similar. My problem was that I wanted to fire an addCookie() function when a user click logged in.

Did that with:

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


This worked for me. the key was realizing that it has to be the html_options hash

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜