0

Given the following helper:

def hide_contact_details!
  @hide_contact_details = true
end

def show_contact_details?
  @!hide_contact_details
end

I want to call hide_contact_details! from a select few controllers and use show_contact_details? around my templates.

However, when I use the view_context object from a controller in Rails 3, it seems to point to a different object than my view.

@hide_contact_details is nil, unless I call hide_contact_details! from within the view, rather than through view_context.hide_contact_details! in the view.

How can I call a (helper)method in the controller, that sets a boolean which is accessible to the helper in the view?

Niels B.
  • 5,912
  • 3
  • 24
  • 44
  • Perhaps `helper_method` would do the trick: http://stackoverflow.com/questions/3992659/in-rails-what-exactly-do-helper-and-helper-method-do – lurker Jun 20 '13 at 16:21
  • This doesn't work. The problem is not the behavior, the problem is the state. Including the helper in the controller just sets the instance variable on the controller, but the (unknown) object that show_contact_details? is mixed into when called from the view, doesn't contain this instance variable. – Niels B. Jun 20 '13 at 16:47

0 Answers0