我正在尝试呈现以下 html:
<a href="<%= INSERT ARTICLE PATH WITH DELETE METHOD HERE %>" class="float-right action-button">
<button type="button" class="btn btn-light">
<%= image_tag("delete", size: "16x16") %>
</button>
</a>
我试过这个没有成功:
<%= link_to(@article, method: :delete, class: "float-right action-button") do %>
<button type="button" class="btn btn-light">
<%= image_tag("delete", size: "16x16") %>
</button>
<%= end %>
我收到以下错误:
SyntaxError in ArticlesController#index
C:/Sites/anais-coaching/app/views/articles/index.html.erb:34: syntax error, unexpected keyword_end ...eze;@output_buffer.append=( end );@output_buffer.safe_append... ... ^ C:/Sites/anais-coaching/app/views/articles/index.html.erb:43: syntax error, unexpected keyword_end, expecting ')' '.freeze; end ^ C:/Sites/anais-coaching/app/views/articles/index.html.erb:47: syntax error, unexpected keyword_ensure, expecting ')' C:/Sites/anais-coaching/app/views/articles/index.html.erb:49: syntax error, unexpected keyword_end, expecting ')'
我想我的问题是我不知道如何使用“link_to xxx do”。谢谢 !
替换这个
<%= link_to @article, method: :delete,, data: {confirm:'Are you sure?' }, class: "float-right action-button") do %>
<button type="button" class="btn btn-light">
<%= image_tag("delete", size: "16x16") %>
</button>
<%= end %>
有了这个
<%= link_to @article, method: :delete, data: {confirm:'Are you sure?' }, class: "float-right action-button" do %>
<button type="button" class="btn btn-light">
<%= image_tag("delete", size: "16x16") %>
</button>
<% end %>
您不需要为 . 添加 <%= %> end
。如果错误已解决,请告诉我。请检查link_to 的文档。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句