mercredi 26 juillet 2017

Emebedded Ruby: Short If Statement

I'm currently learning ruby but I cant get my embedded ruby to work proberly and help would be appreciated.

I'm basically trying to write the short version of this if statement in my embedded ruby

<% entity.attributes.each do |key, value| %>
  <%= if key == "name"
        link_to @entity, edit_entity_path(entity)
      else 
        value
      end %>
<%= end %>

According to my understanding (and this post) it should be as able to write it like this

<% entity.attributes.each do |key, value| %>
  <%= key == "name" ? link_to @entity, edit_entity_path(entity) : value %>
<%= end %>

This doesn't seem to work. What am I doing wrong?

Ralils Error Message: syntax error, unexpected tIVAR, expecting keyword_do or '{' or '(' ...ey == "name") ? ...

Thx in advance for your help

Aucun commentaire:

Enregistrer un commentaire