the variables they have @
are instance variables in the current object scope.
the variables without @
are local variables in the current object scope.
In the specific case of Rails, the variables with @
used in the controllers are available to be used "inside" the views.
To the each
which was quoted follows the example below:
@posts.each do |post|
<faz alguma coisa com 'post' aqui>
end
in this code snippet, the variable post
is local to the scope of the block in which it was defined, so it exists only within the block do |post| ... end
To better understand the differences between the types of variables, classes and objects, take a look at this link http://aprendaaprogramar.rubyonrails.com.br/index.rb?Chapter=09.
About the each
, look here http://aprendaaprogramar.rubyonrails.com.br/index.rb?Chapter=07
Great site you passed. I started learning Rails without mastering 100% Ruby, so some things go unnoticed.
– user7261