This is the first time I've run into an issue like this.
I've been using focused_controller in some projects and in others I've just extracted the expose method (see below). Everything was always fine.
Now in a CRM app I have a CommentsController that handles comments for multiple commentable resources – e.g. a contact. The comment form is currently always displayed on the resource's show page. So in case of errors (e.g. empty comment text), the commentable's show template is the one that needs to be re-rendered in order to properly show error messages. I don't want to do ugly stuff like redirect with error messages in the GET parameters or put something in the session.
As it stands, I found two solutions that actually work and allow me to use contact (as a method call) in the show template:
- Use a combination of
instance_variable_set/get/defined?. Remember: the commentable is essentially polymorphic so I have to set the name dynamically.