rails按钮用单个quute替换引号



我试着应该得到button_to,但没有qoutes

渲染时

button_to "Delete",
  radio_tag_path(tag),
  :method=>:delete,
  :class=>:destroy,
  :confirm=>"Are you sure?"

输出是

<form action="/radio/tags/654" class="button_to" method="post">
  <div>
    <input name="_method" type="hidden" value="delete" />
    <input class="destroy" data-confirm="Are you sure?" type="submit" value="Delete" />
    <input name="authenticity_token" type="hidden" value="eXM0McnTzuhnYIxrLLYF7kjp76fdMdZpq6HPc++ogog=" />
  </div>
</form>

但我需要没有qoutes的

比我渲染的

(button_to "Delete",
  radio_tag_path(tag),
  :method=>:delete,
  :class=>:destroy,
  :confirm=>"Are you sure?"
).gsub('"',''')

但是输出类似于html_safe

&lt;form action=&quot;/radio/tags/654&quot; class=&quot;button_to&quot; method=&quot;post&quot;&gt;&lt;div&gt;&lt;input name=&quot;_method&quot; type=&quot;hidden&quot; value=&quot;delete&quot; /&gt;&lt;input class=&quot;destroy&quot; data-confirm=&quot;Are you sure?&quot; type=&quot;submit&quot; value=&quot;Delete&quot; /&gt;&lt;input name=&quot;authenticity_token&quot; type=&quot;hidden&quot; value=&quot;eXM0McnTzuhnYIxrLLYF7kjp76fdMdZpq6HPc++ogog=&quot; /&gt;&lt;/div&gt;&lt;/form&gt;

我如何删除引号,但仍然使用html标签

您需要更正两件事:

  • 匹配双引号的gsub调用
  • 将输出标记为html安全

比如:

button_to("Delete", radio_tag_path(tag),
  :method=>:delete, :class=>:destroy, :confirm=>"Are you sure?"
).gsub('"',''').html_safe

相关内容

  • 没有找到相关文章

最新更新