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

有帮助吗?

解决方案

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top