Boltz0r
Boltz0r

Reputation: 980

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.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

Answers (3)

venkatKA
venkatKA

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

potashin
potashin

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

loving marshmallow
loving marshmallow

Reputation: 331

You can't use <%= %> within <%=%>. Instead, use #{} for the within. Like ...('#{prato.id}')...

Upvotes: 1

Related Questions