2012-08-12 151 views
1

我是Rails框架和Ruby語言的新手,但我確實有一些編程和MVC經驗。我正在嘗試使用rails的link_to方法輸出鏈接。但是,在HTML中,此鏈接位於另一組雙引號內。我需要避開標籤中由rails生成的引號。在Rails中轉義雙引號link_to

我已經嘗試谷歌,只發現JavaScript轉義哪些沒有幫助的信息。我嘗試過使用一個h(%[])方法,這個方法曾經被提過幾次,但是這個鏈接並沒有被創建,實際的單詞link_to已經被使用了。

有誰知道我如何逃避由rails創建的超鏈接標籤中的雙引號或將其切換爲使用單引號?

實際代碼

<% @properties = Property.all 
          @properties.each do |property| %> 
          <img src="images/img<%= property.id %>.jpg" alt="" title="<strong><%= property.address %></strong><span>9 rooms, 3 baths, 6 beds, building size: 5000 sq. ft. &nbsp; &nbsp; &nbsp; Price: $ 600 000 &nbsp; &nbsp; &nbsp; <%= link_to "Read More", property) %></span>"> 
          <% end %> 

輸出

<img src="images/img1.jpg" alt="" title="<strong>50 Craft LAne</strong><span>9 rooms, 3 baths, 6 beds, building size: 5000 sq. ft. &nbsp; &nbsp; &nbsp; Price: $ 600 000 &nbsp; &nbsp; &nbsp; <a href="/properties/1">Read More</a></span>"> 

超鏈接的第一個雙引號與標題配對=」然後一切都關閉

+0

請出示您正在嘗試的實際代碼。它會幫助你獲得更多答案。 – 2012-08-12 19:17:19

+0

編輯原始帖子以包含代碼和輸出 – user1593858 2012-08-12 19:27:04

回答

2

你可以做這樣的事情:

<%= link_to("Read More", property).gsub("\"", "'") %> 
+0

工作正常。謝謝 – user1593858 2012-08-12 20:17:35

0

的link_to ' 「東西」'

不起作用舉一個你想要的例子