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

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -