Forum: Ruby on Rails RE: Defining a variable in the environment and using itincon

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
HOGANBP (Guest)
on 2005-11-16 19:02
(Received via mailing list)
Well, environment is done once... So @pagemeta won't work because it's a
scope issue. You can, however, create and set constants in the
environment.rb file, but you won't be able to override them.

Here's one way to achieve what you're trying to do:

In /controllers/application.rb

# put this right after the class definition:
before_filter :setup

# set up any global variables that you want to use.
# Call this through a filter so it's called on every request.
def setup

 @pagemeta = {:title       => 'Default page title',
            :description => 'Default page description',
             :keywords    => 'Default page keywords'}
end



Then you should be able to use the variable in your pages.

Does that help?
This topic is locked and can not be replied to.