我有friendly_id
正確設置,並且所有的東西都可以使用,使用slu。子彈。FriendlyID不會構建HTML轉義子彈
我遇到的問題是我的Tag
模型(這是FriendlyId所連接的模型)上的一些名稱需要HTML轉義。
像c++
或.net
這樣的名稱。
當我跑Tag.find_each(:&save)
,它產生的所有的蛞蝓,我....但與這些名字這些標籤,這是發生了什麼事:
> c = Tag.where(:name => "c++")
Tag Load (0.9ms) SELECT "tags".* FROM "tags" WHERE "tags"."name" = 'c++'
=> [#<Tag id: 2, name: "c++", num_questions: 187598, created_at: "2013-03-23 07:02:09", updated_at: "2013-03-29 15:34:09", questions_count: 87, slug: "c">]
> Tag.where(:name => ".net")
Tag Load (0.9ms) SELECT "tags".* FROM "tags" WHERE "tags"."name" = '.net'
=> [#<Tag id: 142, name: ".net", num_questions: 149074, created_at: "2013-03-23 07:09:47", updated_at: "2013-03-29 15:34:10", questions_count: 85, slug: "net">]
1.9.3p392 :012 > Tag.where(:name => "c#")
Tag Load (1.0ms) SELECT "tags".* FROM "tags" WHERE "tags"."name" = 'c#'
=> [#<Tag id: 38, name: "c#", num_questions: 435620, created_at: "2013-03-23 07:03:27", updated_at: "2013-03-29 15:34:10", questions_count: 130, slug: "c--3">]
通知每個那些蛞蝓 - 以及如何他們不符合每條記錄的name
。
我該如何解決這個問題?
Soo ....沒有那麼複雜...我怎麼才能讓這些簡單的名字像我想要的那樣工作? – marcamillion
我認爲你需要slu to出現在URL中?如果是這樣,你想如何處理像這樣的「問題人物」?特別是'#'符號,您必須替換它或對其進行網址編碼。 –
正如你正確指出的那樣,'normalize_friendly_id'所做的就是調用stringize上的'parameterize' - https://github.com/norman/friendly_id/blob/master/lib/friendly_id/slugged.rb#L244我想要的但要做的是讓這些字符串工作。當我在我的Rails控制檯中執行'c#.parameterize'時,我得到'>「c#」。參數化 =>「c」'這正是我不想要的。 – marcamillion