Boltz0r Boltz0r - 1 year ago 119
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

Answer Source

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}')"
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download