I have following view file and I need to reference views instance variable in .js.erb
file.
<div class="container">
<table class="table no-border">
<% @leads.each_slice(2) do |slice| %>
<tr>
<% slice.each do |lead| %>
<td class="col-sm-6 col-md-6" style="border: none;">
<div class="panel panel-default" style="border: solid #E0E0E0 1px;">
<div class="panel-heading custom-panel-heading" style="background-color: #F0F0F0;">
<%= form_for :email_form, :html => {:class => "form-horizontal"}, url: search_reduce_credits_by1_path, id: "candidate-email-modal-form", remote: true do |f| %>
<%= f.hidden_field :lead_id, :value => lead.id %>
<div class=text-right>
<%= f.button class: "btn btn-primary", id: "show-mail-btn" do %>
Show Email
<% end %>
</div>
<small class="blurfilter" id="blurred_email_<%= lead.id %>" data-query="blurred_email_<%= lead.id %>"> <%= lead.email %> | <%= lead.id %></small>
<% end %>
</td>
<% end %>
</tr>
<% end %>
</table>
</div>
How do I reference <%= lead.id %>
in .js.erb file?
var x = $(".blurfilter").data("query");
alert(x);
Its not working as of now.
If lead
is instance variable ie @lead
then it should be directly accessible in your js.erb. file. In js.erb you can write it like this "<%= lead.id %>".
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.