I would like to declare a variable in my application_controller.rb
controller that is accessible to all controllers that inherit from it. if possible I would like the variable only accessible in the child classes, nowhere else, including the views (unless specifically passed into the view).
I am new to Ruby and Rails and am unsure if the "protected" scope exists for variables, I have seen that it does for functions. I have not been able to find a simple answer and I have been experimenting a little in my app with different ways to declare variables and where they can be accessed. That has provided me with no information about how I can accomplish this.
Any help would be greatly appreciated.
Code:
class ApplicationController < ActionController::Base
protect_from_forgery
@admin_name = "AdminUserName"
@admin_password = "AdminPassword"
end
class ProjectsController < ApplicationController
http_basic_authenticate_with :name => @admin_name, :password => @admin_password, :except => [:index, :show]
# controller functions here
end
This does not seem to be working for me.