Domanda

I'm trying to pass the result of (if ... else) to .erb file for example

if @p
 "show something"
else    
 "show other thing"
end

How could I do it? Thanks

È stato utile?

Soluzione

The usual way of passing values to the view in Sinatra is by using instance variables. Any instance variable you set in your route will be available in the view. So in this case you could do something like this:

@my_variable = if @p
 "show something"
else    
 "show other thing"
end

and then in your Erb view:

<%= @my_variable %>

The result will be that either show something or show other thing will appear in the rendered page depending on the value of @p.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top