at the top of my controller, outside of any method, I have
@@javascript_is_disabled = false
and I have methods that that the view calls and invokes something like this
@@javascript_is_disabled = params[:javascript_disabled]
but when I need the @@javascript_is_disabled in completely different method.. it is always false.
I know it changes in the method with params args… cause those methods behave differently, and appropriately
And ideas?
The variable
@@javascript_is_disabledis a class variable and it refers to a different thing depending on where you access it from. From within the Controller class body it doesn’t refer to the same thing as when you use it from within a controller method or a view. This is actually a pretty complex subject involving EigenclassesI suggest implementing it using a view helper or a protected method:
Then you can reference it from within your views and controller action methods like an attribute
javascript_is_disabled = trueorif javascript_is_disabled ...You could also leave out the
attr_writer ...part and just always remember to assign values to the instance variable@javascript_is_disabled = ...