加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails – Haml格式化

发布时间:2020-12-17 03:51:26 所属栏目:百科 来源:网络整理
导读:我是haml的新手,所以我还在试图找出格式. 我有一个index.haml文件,其中包含以下代码. %h1 Welcome to SolidarityHello,= @profile.first_name! 它呈现如下: Welcome to Solidarity Hello,user ! 这是页面来源: h1 Welcome to Solidarity/h1Hello,frances!
我是haml的新手,所以我还在试图找出格式.

我有一个index.haml文件,其中包含以下代码.

%h1
  Welcome to Solidarity

Hello,= @profile.first_name
!

它呈现如下:

Welcome to Solidarity
Hello,user !

这是页面来源:

<h1>
  Welcome to Solidarity
</h1>
Hello,frances
!

它在@ profile.first_name和感叹号之间有一个空格.这是为什么?而且,我该如何解决?

解决方法

%h1 Welcome to Solidarity
Hello,#{@profile.first_name}!
Please #{link_to 'post a comment',new_comment_path}!

<h1>Welcome to Solidarity</h1>
Hello,John!
Please <a href="/comments/new">post a comment</a>!

请记住,在Rails 2和Haml 2中,你必须正确html-escape你发送到浏览器的任何东西(ht nex3):

Hello,#{h @profile.first_name}!

在Rails 3和Haml 3中,默认情况下都会转义所有内容,因此您可以执行以下操作:

Hello,#{@profile.first_name}!

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读