mardi 1 août 2017

if-else statement ignored on RubyonRails view (html.erb)

I have a weird situtation with a RubyOnRails if-else statement.

I have an string named pregunta[1] which I obtained in this way:

pregunta[1] can have 3 possible values: (+), (-) or (?)

After that pregunta[1] is assigned to another string named modo in this way:

<%= modo = pregunta[1] %>

Depending of the value of modo, I need to display different things, in order to do that I need 3 different if-else statements:

<%= modo %>

<% if modo == "(+)" %> Write something to modo afirmativo <% end %>

<% if modo == "(?)" %> Write something to modo interrogativo <% end %>

<% if modo == "(-)" %> Write something to modo negativo <% end %>

I put the first line <%= modo %> in order to check that I am reciving the right value. And it is not adding other stuff like \n or something.

On the browser, the .erb.html view, is showing the first line modo value perfectly with the right value, but the three different if-else statements are completely ignored.

I think, it should have something to do with my sintaxis, because I tried a case statement with the same result.

It is not an option to write the code on the controller, I need to have it on the view. Because it is part of another code which I need to have in there.

Any idea about what I am doing wrong?

Thank you. =)

Aucun commentaire:

Enregistrer un commentaire