简体   繁体   中英

How do I add class tag to this rails link_to tag in slim?

I wanted to add class name 'button' to this following tag.

= link_to 'Upload data', new_raw_datum_path if logged_in?

So I tried this,

= link_to 'Upload data', new_raw_datum_path if logged_in?, class: 'button'

but it gave me back this error

syntax error, unexpected ',', expecting ')'
...w_raw_datum_path if logged_in?, class: 'button'), true, "\n ...
... 

My way of adding a class name worked fine in other pages but not this page. (This is a link in my navigation)

How could I add them in slim??? Thank you for your time. ^

它应该是:

= link_to 'Upload data', new_raw_datum_path, class: 'button' if logged_in?

You can use link_to_if of rails actionview:

= link_to_if(logged_in?, "Login", new_raw_datum_path, class: 'button') do
    link_to 'Upload data', new_raw_datum_path
  end  

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