Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between <%= expression %> and <%= expression -%> on Ruby On Rails [duplicate]

Possible Duplicate:
Difference between -%> and %> in rails

I need to know what is the difference between <%= expression %> and <%= expression -%> on rails, please help me to make good foundation on Ruby On Rails

like image 681
Senthil Kumar Bhaskaran Avatar asked Oct 14 '09 07:10

Senthil Kumar Bhaskaran


People also ask

What is the difference between a statement and an expression in Ruby?

There is no difference between expressions and statement is Ruby. Everything evaluates to a value so everything is an expression.

What does #{} mean in Ruby?

It is for String Interpolation.. In Ruby, there are three ways of interpolation, and #{} is just one way. apples = 4 puts "I have #{apples} apples" # or puts "I have %s apples" % apples # or puts "I have %{a} apples" % {a: apples}


2 Answers

The '-%>' means, that no linebreak will be appended to the output of the expression. It's usefull if you want to control the amount of whitespace you have in the generated HTML but do not want to put all the code in a single line.

like image 96
Tomas Markauskas Avatar answered Oct 27 '22 00:10

Tomas Markauskas


As mentioned before, the -%> is used to control output whitespace. I you're at all concerned with how your HTML looks, use HAML. HAML is way more clear and readable when coding and it generates clear, valid formatted HTML. No more forgotten close tags!

like image 27
Ariejan Avatar answered Oct 27 '22 00:10

Ariejan