Boltz0r Boltz0r - 8 months ago 39
Ruby Question

Passing Ruby var as Javascript Parameter

I want to pass a ruby var as a javascript function param in a Rails checkbox, like this:

<%= check_box_tag 'Sugestão', , 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


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}')"