在f.select onchange函数中传递一个ruby变量

时间:2018-11-16 06:19:41

标签: ruby-on-rails

代码如下。

 <% account_id = @account.id %>
    <%= f.select :white_count, options_for_select((1..7), f.object.try(&:white_count)), { label: 'Please select how many fields there are in white', include_blank: '--Select--' }, class: "white-count-#{@water_meter.id}", onchange: 'displayReadingBlocks()' %>

我需要将account_id作为参数传递给javascript函数displayReadingBlocks()。

关于如何执行此操作的任何想法?

1 个答案:

答案 0 :(得分:0)

使用字符串插值实现

<%= f.select :white_count, options_for_select((1..7), f.object.try(&:white_count)), { label: 'Please select how many fields there are in white', include_blank: '--Select--' }, class: "white-count-#{@water_meter.id}", onchange: "displayReadingBlocks(#{account_id})" %>