Unwanted whitespace in Erb view
Here's my sinatra code:
get '/' do
foo = 'not bar'
erb :index
end
My layout.erb
<html>
<head></head>
<body>
<%= yield %>
</body>
</html>
My index.erb
<div class="container">
</div>
now the problem is
The extra text (hilighted with yellow) disturbs my design Any idea why this is happening? this dosn't happen if I dont use layout and use only index.erb with all html code
[Edit:] Use开发者_运维百科 of <%= yield -%> throws error (unexpected tUMINUS, expecting kEND ; @_out_buf.concat " "; - yield -; @_out_buf.concat "\n" ) in .... layout.rb
my best guess is the 4 spaces come from the soft tabs in your layout.erb
<body>
____<%= yield %>
</body>
try <body><%= yield%></body>
?
I've been using Slim a long while and
body
= yield
never fails me whitespace
hate ERB
You can set this up with *trim_mode* parameter for ERB
From http://ruby-doc.org/stdlib-1.9.3/libdoc/erb/rdoc/ERB.html#method-c-new :
If trim_mode is passed a String containing one or more of the following modifiers, ERB will adjust its code generation as listed:
% enables Ruby code processing for lines beginning with %
<> omit newline for lines starting with <% and ending in %>
> omit newline for lines ending in %>
精彩评论