【问题标题】:How to pass embedded ruby code as ID parameter in Rails如何在 Rails 中将嵌入的 ruby​​ 代码作为 ID 参数传递
【发布时间】:2013-12-18 09:10:47
【问题描述】:

注意 :id 部分:

<% form_tag session_path, :id => 'elm_id_<%=  @product.count %>',
        :class => 'elm_class', :style => 'elm_style' do -%>


   # My Codes goes here

<% end -%>

在这里,我想用默认文本“elm_id”附加产品计数,并将整个事物设置为 ID。但是上面的代码不起作用。 :(

【问题讨论】:

    标签: ruby-on-rails forms form-for


    【解决方案1】:

    您已经在表单的 Ruby ERB 标记中,在字符串中不再需要它们。您需要插入字符串,因此:

    <% form_tag session_path, :id => "elm_id_#{@product.count}", ...
    

    【讨论】:

    • 您需要一个双引号字符串 - "elm_id_#{@product.count}" - 因为 #{} 不会被解释为单引号字符串。
    猜你喜欢
    • 2011-01-28
    • 2011-04-28
    • 2016-02-27
    • 2014-01-06
    • 1970-01-01
    • 1970-01-01
    • 2013-08-10
    • 1970-01-01
    • 2020-11-16
    相关资源
    最近更新 更多