سؤال

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