【问题标题】:how to use link tag in Ruby on Rails如何在 Ruby on Rails 中使用链接标签
【发布时间】:2014-02-12 06:45:26
【问题描述】:

如何在 ruby​​ on rails 中使用链接标签?

<%  link_to "Stephen Weber", "home.html" %>   

【问题讨论】:

标签: ruby-on-rails ruby ruby-on-rails-3


【解决方案1】:

你错过了=,应该是&lt;%=

<%=  link_to "Stephen Weber", "home.html" %>

【讨论】:

  • 我没有得到正确的输出。它说 No route matches "/home.html" with {:method=>:get} 我该怎么办?请帮助我。谢谢你的提前
【解决方案2】:

这取决于您使用的视图渲染引擎的类型,如果您使用的是 Haml-rails,那么语法会略有不同,请记住 Haml 视图是基于缩进的,就像 python 一样:

= link_to "Stephen Weber", "Home.html", {class: 'any_class_name', id: 'try_to_use_unique', style: 'margin:'''}

如果你使用的是erb,那么语法是:

 <%= link_to "Stephen Weber", "Home.html", {class: 'any_class_name', id: 'try_to_use_unique', style: 'margin:'''} %>

【讨论】:

    【解决方案3】:

    你错过了=

    <% link_to "Stephen Weber", "home.html" %>
    

    应该是

    <%= link_to "Stephen Weber", "home.html" %>
    

    有关 Rails ERB 格式的更多详细信息,请转到Why many people use "-%>" instead of "%>" in Rails?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-09-15
      • 1970-01-01
      • 2013-09-02
      • 2012-03-08
      • 1970-01-01
      • 2011-01-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多