Is it possible to refer to ruby class variables in a view?
The more common approach is to wrap the class variable in a helper method:
# in /app/controllers/foo_controller.rb:
class FooController < ApplicationController
@@bar = 'baz'
def my_action
end
helper_method :bar
def bar
@@bar
end
end
# in /app/views/foo/my_action.html.erb:
It might be a class variable, or it might not, but bar is "<%= bar -%>."
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With