문제

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