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
There is no difference between expressions and statement is Ruby. Everything evaluates to a value so everything is an expression.
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}
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.
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!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With