I have a button and I want to set its onClick attribute dynamically each page load. I want to use application_helper to give it a custom javascript every time. It seems difficult to do because the Javascript is going to need access to stuff that only the ruby has access to. I wanted to build up a custom javascript with the application_helper module and yield the result of calling the helper method as the value to the onClick key in the Haml hash:
In application.html.haml:
%button{class: "user_navigation_menu_item", onClick: = gimme_my_custom_javascript}
In application_helper,rb:
def gimme_my_custom_javascript
javascript = "function(){"
javascript +="alert('yo!');"
javascript+="}"
end
Haml is yelling at me: ‘unexpected “=”‘
How do I do what I am trying to do?
Thank you
Just get rid of the
=and it should work: