2013-08-26 24 views
0

我嘗試應該得到button_to但沒有qoutes軌button_to單quoute

取代報價在渲染

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標籤

+0

你爲什麼要更換雙引號? – jvnill

+0

你是說你想刪除標籤屬性的所有引號?雖然其中一些將是不帶引號的有效HTML,但如果刪除了所有引號,則會導致HTML無效。你通過這樣做想達到什麼目的? – Planty

+0

答案似乎很簡單,但爲什麼要這樣做呢? – Bigxiang

回答

1

您需要更正兩件事情:

  • GSUB通話匹配雙引號
  • 將輸出標記爲html安全

就像是:

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

感謝它實際上按預期工作。 – 24sharon