2

目前我有鐵路後端骨幹RIA。我使用haml_coffee_assets gem進行客戶端模板。但我想念那裏的鐵觀點幫手。如何將原始html字符串屬性嵌入到.hamlc模板中?

我決定將原始html字符串添加到我的主幹模型中。 所以,我有這樣的對象在我的CoffeeScript

Object 
    avatar: "/avatars/small/missing.png" 
    avatar_link: "<a href="https://stackoverflow.com/users/ortepko" class="author" id="user-nick-76"><img src="/avatars/small/missing.png" width="32" /></a>" 
    humanized_messages_number: "1 Message " 
    id: 76 
    login_name_link: "<a href="https://stackoverflow.com/users/ortepko" class="author" id="user-nick-76">ortepko</a>" 

我的模板代碼變得非常簡單

.text_content 
    .comment 
    = @contact.avatar_link 
    .text 
     = @contact.login_name_link 
     .messages 
     %a{href: '#'} 
      = @contact.humanized_messages_number 

現在我想呈現模板

JST['messages/yet_another_template'] {contact: contact} 

但事實並非如此似乎工作。

+0

剛剛在這裏找到了答案: http://stackoverflow.com/questions/9201593/partials-in-coffee-haml-hamlc – Ortepko

回答

6

我已經在這裏找到了答案: Partials in Coffee HAML (.hamlc)

我的模板應該像

.text_content 
    .comment 
    != @contact.avatar_link 
    .text 
     != @contact.login_name_link 
     .messages 
     %a{href: '#'} 
      = @contact.humanized_messages_number 

感謝Netzpirat!

+0

謝謝!你保存我的應用程序! :D –

+0

安全嗎?像XSS問題? –

+0

@DmitryPolushkin,XSS的安全取決於你。在我的情況下,我已經將HTML呈現給服務器端的json對象,並對它的安全性有完全的控制 – Ortepko

相關問題