Carlos Melo
Carlos Melo

Reputation: 3152

View can't see instance variable defined in ApplicationController, in Rails

Hey guys! I'm getting a problem that is driving me crazy.

I defined an instance variable inside my ApplicationController:

def initialize
    @stylesheets = []
end

When I try to access it from a view, say SomeNamespace::SiteSection (index.html.erb):

<% @stylesheets << "some-stylesheet" %>
<h1>Blablabla</h1>

the instance variable @stylesheets isn't visible, i.e., ruby says it wasn't defined.

So, how I make this instance variable visible inside the views?

Thanks in advance.

Additional info:

Upvotes: 2

Views: 3348

Answers (1)

fl00r
fl00r

Reputation: 83680

class ApplicationController < ActionController::Base
  protect_from_forgery
  before_filter :set_var

  private
  def set_var
    @stylesheets = []
  end
end

Upvotes: 10

Related Questions