1

I've frequently seen code like this in ERB templates:

<%= @some_variable %>

And seen code like this:

<%= node[:some_attribute][:some_other_attribute] %>

And just plain old

<%= some_variable %>

Is there a difference? Should I be concerned?

Jacklynn
  • 1,503
  • 1
  • 13
  • 23

1 Answers1

1

Generally the @ is used if it is an instance variable. The most common use of these will be in a controller when you want to pass a variable up to the view that will render it.

For example you might have

class FooController < ApplicationController

def show
    @foo = Foo.find_by_id(params[:id]) 
end

end

And then in the corresponding show page you could access foo by calling:

<%= @foo.bar %>

This is useful when you will be rendering many show pages with many different foos.

NateSHolland
  • 1,130
  • 2
  • 11
  • 25