vendredi 23 mars 2018

Rails: how to create a list with conditional links

I am working on a RAILS application where I create a view which lists all available resources of a given model species.rb.

The view partial is:

<% i= @s
for species in @species %>
    <%= species.name %>, <%= species.author.surname %> <%= species.author.initial_name %>
<%  i -= 1
    end %>

Some of the resources species have an related article, others have only the name. I would like to loop through the partial and add a link only to the entries which have an associated article.

Something like: add link if species.article is present else just put species.name without link + loop through it for all entries.

How can I do this?

Aucun commentaire:

Enregistrer un commentaire