Hirohito Yamada
Hirohito Yamada

Reputation: 387

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. ^

Upvotes: 1

Views: 2552

Answers (2)

HashRocket
HashRocket

Reputation: 798

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  

Upvotes: 0

sebsonic2o
sebsonic2o

Reputation: 356

It should be:

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

Upvotes: 5

Related Questions