I'm a ruby/rails newbie and need to make a hash which can be manipulated anywhere in the rails application and can be accessed by all views just like the flash[:notice] hash. Is this possible?
Asked
Active
Viewed 159 times
1
-
This may help http://stackoverflow.com/questions/3598785/where-to-put-global-variables-in-rails-3 – halfelf Oct 10 '12 at 09:22
2 Answers
1
This should work:
class ApplicationController < ActionController::Base
def block
@block ||= {}
end
helper_method :block
end
block[:foo] = "FOO"
block[:foo] #=> "FOO"
However, what you are trying to do is normally done with the help of content_for

doesterr
- 3,955
- 19
- 26
0
Yes, you can do it. Any key/value pair can be stored in flash. for example,
flash[:email] = 'abc@yahoo.com'
flash[:username] = 'abc'
flash[:xyz] = 'xyz'
These values can be accessed any where in controllers and views, just like flash[:notice]
and flash[:error]

Ramiz Raja
- 5,942
- 3
- 27
- 39