Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/56.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails Ruby没有';t显示标签按钮上的按钮\u_Ruby On Rails_Ruby - Fatal编程技术网

Ruby on rails Ruby没有';t显示标签按钮上的按钮\u

Ruby on rails Ruby没有';t显示标签按钮上的按钮\u,ruby-on-rails,ruby,Ruby On Rails,Ruby,您好,我正在阅读关于RubyonRails的指南“使用Rails4进行敏捷Web开发”,我正在我的计算机Ruby1.9.3上运行 在Interxtion 9.3中,我尝试创建一个按钮,用于创建带有标记按钮的LineItem <%= button_to 'Add to Cart', line_item_path(product_id: product) %> 但是当我尝试在localhost中执行代码时,按钮没有出现 Ruby 1.9.3中是否有此标记的代码变体?看起来您的语法有

您好,我正在阅读关于RubyonRails的指南“使用Rails4进行敏捷Web开发”,我正在我的计算机Ruby1.9.3上运行

在Interxtion 9.3中,我尝试创建一个按钮,用于创建带有标记按钮的LineItem

<%= button_to 'Add to Cart', line_item_path(product_id: product) %>

但是当我尝试在localhost中执行代码时,按钮没有出现


Ruby 1.9.3中是否有此标记的代码变体?

看起来您的语法有问题:

<%= button_to raw("<i class=\"icon-search icon-white\">Add To Cart</i>"), 
          line_items_path(product_id: product), 
          class: "btn btn-success" %>

用双引号括住按钮的标签,转义i标记中的双引号,最后,将所有内容包装到raw()调用中,以确保正确显示HTML

或者,您可以使用html_-safe:

<%= button_to "<i class=\"icon-search icon-white\">Add To Cart</i>".html_safe, 
          line_items_path(product_id: product), 
          class: "btn btn-success" %>

除非您绝对需要button_to helper提供的表单创建功能,否则您可能希望使用link_to或button_标记,这两种标记都会占用块

<%=button_tag class: "btn btn-success" do %>
  <i class="icon-search icon-white">Add to Cart </i> 
<%end%>

<%=link_to products_path, class: "btn btn-success" do %>
  <i class="icon-search icon-white">Add to Cart &nbsp;</i> 
<%end%>

添加到购物车
添加到购物车

希望这能有所帮助。

这是rails方法,所以运行Ruby 2.x或1.9.3没有什么区别。检查正在生成的HTML。如果没有更多上下文,则很难知道,但请尝试删除
产品id:
,使其成为
,然后查看发生了什么。尽管如此,我还是假设您应该将行项目路径传递为“行项目”…?您粘贴的代码可以工作。所以问题很可能在页面的其他地方。尝试使用页面上的其余代码更新您的问题。我的猜测是页面上有另一个元素没有按预期关闭。我认为这不是语法错误。我尝试了你的代码,但执行时它不会生成html