【问题标题】:Refactoring ERB to HAML - Ruby code inside ruby code in one line将 ERB 重构为 HAML - Ruby 代码中的 Ruby 代码在一行中
【发布时间】:2014-12-12 22:47:21
【问题描述】:


我有一个小问题,不知道如何处理我的问题。
我一直在寻找问题的答案,但没有找到任何东西。

我想将erb重构为haml。
我的问题是 - 如何像这样重构部分代码(一行中的 ruby​​ 代码中的 ruby​​ 代码):

<%%= render partial: '<%= singular_table_name %>', collection: @<%= plural_table_name %>, locals: {f: f} %>

http://html2haml.com 答案是:

<%= render partial: '<%= singular_table_name %>', collection: @#{plural_table_name}, locals: {f: f} %>

但我不认为这是个好主意......

【问题讨论】:

    标签: ruby-on-rails ruby haml erb


    【解决方案1】:
    = render partial: singular_table_name, collection: @plural_table_name, locals: {f: f}
    

    【讨论】:

    • 谢谢。还有一个问题。如何重构:_path, html: {method: :get, class: 'filter-form'} do |f| %>
    • 这应该可以工作:= form_for :filter, url: "admin_#{index_helper}_path, html: { method: :get, class: 'filter-form' } do |f|
    • 这对你有用吗?此外,如果答案正确回答了您的问题,请考虑将答案标记为已接受。
    猜你喜欢
    • 1970-01-01
    • 2014-07-23
    • 1970-01-01
    • 1970-01-01
    • 2023-03-09
    • 1970-01-01
    • 2011-10-01
    • 2014-06-26
    • 2013-01-13
    相关资源
    最近更新 更多