ruby - Purpose of @ in ERB templates -
ruby - Purpose of @ in ERB templates -
this question has reply here:
@ variables in ruby on rails 6 answersi've seen code in erb templates:
<%= @some_variable %> and seen code this:
<%= node[:some_attribute][:some_other_attribute] %> and plain old
<%= some_variable %> is there difference? should concerned?
generally @ used if instance variable. mutual utilize of these in controller when want pass variable view render it.
for illustration might have
class foocontroller < applicationcontroller def show @foo = foo.find_by_id(params[:id]) end end and in corresponding show page access foo calling:
<%= @foo.bar %> this useful when rendering many show pages many different foos.
ruby syntax erb
Comments
Post a Comment