How to add a condition in a Select form tag?


i ve got this piece of code :
<%= select(“profile”, “vlogiciel”, @vlogiciel.collect {|vlogiciel|
[ vlogiciel.logiciel.nom, ] }, :include_blank=>true, :selected=>(@vl).to_i )%>

But i would like to do that

<%= select(“profile”, “vlogiciel”, @vlogiciel.collect {|vlogiciel|
[ vlogiciel.logiciel.nom + vlogiciel.lversion.nom, ] }, :include_blank=>true, :selected=>(@vl).to_i )%>

But sometime vlogiciel.lversion is NULL,
so i need to add an unless condition like that :

<%= select(“profile”, “vlogiciel”, @vlogiciel.collect {|vlogiciel|
[ vlogiciel.logiciel.nom +
unless vlogiciel.lversion == nil
end, ] }, :include_blank=>true, :selected=>(@vl).to_i )%>

There is synthax error so it s not working.
i can t figure out how to add a conditions into this select…

Does anyone have an idea ?


Assemble your collection for the select in the controller where you have
free reign on how the data is brought together and/or massaged for

Or use an immediate if (or whatever Ruby calls it)

[vlogiciel.logicial.nom+(vlogicial.lversion.nil? ? ‘’ :

Haven’t tried it myself, but that is left as “an exercise for the

You are my star :slight_smile:

Thanks so much !!!

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs