简体   繁体   中英

HAML add href if

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. An href with an empty string didn't do the job, but getting rid of the href altogether seems to work.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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