Hello, where do we need <% -%> in templates ? What is the difference between <%= %> and it ? -- Posted via http://www.ruby-forum.com/.
<%= %> will execute the contained ruby and inject the result into the document. <% %> will execute the contained ruby, but will NOT inject anything into the document (other than a blank line) .... hence ... <% -%> will execute the contained ruby and will not inject anything into the document (not even a blank line). -Derrick Spell On Mar 20, 2006, at 3:23 PM, Firstname Secondname wrote:> Hello, > where do we need <% -%> in templates ? What is the difference between > <%= %> and it ? > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Derrick Spell wrote:> <%= %> will execute the contained ruby and inject the result into the > document. > > <% %> will execute the contained ruby, but will NOT inject anything > into the document (other than a blank line) .... hence ... > > <% -%> will execute the contained ruby and will not inject anything > into the document (not even a blank line). > > -Derrick SpellThank You, Derrick! :) -- Posted via http://www.ruby-forum.com/.
You can also use - with the include. I.e. <%= "blah" -%> This will inject "blah" into the output, but will not create a new line. This is useful when you''re pulling data into something that is surrounded by quotes (like an HREF) where you don''t want the newlines and want to maintain readability. On 3/20/06, Firstname Secondname <mzilenas@gmail.com> wrote:> Derrick Spell wrote: > > <%= %> will execute the contained ruby and inject the result into the > > document. > > > > <% %> will execute the contained ruby, but will NOT inject anything > > into the document (other than a blank line) .... hence ... > > > > <% -%> will execute the contained ruby and will not inject anything > > into the document (not even a blank line). > > > > -Derrick Spell > > Thank You, Derrick! > :) > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >