Reputation: 980
I want to pass a ruby var as a javascript function param in a Rails checkbox, like this:
<%= check_box_tag 'Sugestão', prato.id , prato.sugestao,:class => prato.categoria_pratos_id, :id => "task-check3",:onchange =>"checkbox('<%=prato.categoria_pratos_id%>')" %>
I have the Javascript checkbox Function working fine. But i need to pass the id as the param... It just gives me application error if i do that
Upvotes: 1
Views: 115
Reputation: 2399
It's because what you're giving within <%= %>
is Ruby. You don't have to use the notation again while passing your parameter. Simply use :onchange => "checkbox('#{your_id}')"
Upvotes: 3
Reputation: 44601
You have erb interpolation within erb interpolation, while you just need to interpolate ruby variable in a ruby string :
onchange: "checkbox('#{prato.categoria_pratos_id}')"
Upvotes: 1
Reputation: 331
You can't use <%= %> within <%=%>. Instead, use #{} for the within. Like ...('#{prato.id}')...
Upvotes: 1