简体   繁体   English

HAML添加href如果

[英]HAML add href if

Rails 4 + HAML. Rails 4 + HAML。

Is there any way to consolidate this into one line? 有什么方法可以将其合并为一条线?

- if current_page?(controller: 'root', action: 'sign_up')
    %a Sign Up
- else
    %a{href: program_sign_up_path} Sign Up

The reason is that if the link has an href, it appears to still be clickable and reloads the page on click, whereas if the user is on the sign_up page, the link either shouldn't be clickable or not go anywhere. 原因是,如果链接具有href,它似乎仍然可以单击,并在单击时重新加载页面,而如果用户在sign_up页面上,则该链接要么不可单击,要么不可以随处访问。 An href with an empty string didn't do the job, but getting rid of the href altogether seems to work. 带有空字符串的href不能完成这项工作,但是完全摆脱href似乎是可行的。

%a{href: ( program_sign_up_path unless current_page?(controller: 'root', action: 'sign_up')) } Sign Up

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM