ruby - Strings passed from controller to view in Rails arrive empty -
i trying pass string view controller this:
controller:
def index @str = 'foo' end
view:
string: <% @str %>
the variable seems arrive because no error. however, arrives empty (only "string" in html, nothing else). , seems work great other built-in types, e.g. time. missing here? use ruby 2.2.1 , rails 4.
as others have said, need use
<%= @str %>
i'll give explanation - use <% %>
when need run ruby code don't want displayed screen. example, might have conditional logic
<% if user_signed_in? %> <%= @welcome_string %> <% end %>
use <%= %>
when want output, drop '=' conditional logic or doesn't need display.
Comments
Post a Comment