I would like to add a status concern to various controllers since all of these controllers share the same status functionality.
A status can be "active", "inactive" or "archived". If added to a specific controller ex. bars_controller these methods would look like this:
def activate
@bar.activate!
redirect_to(:back)
end
def deactivate
@bar.deactivate!
redirect_to(:back)
end
def archive
@bar.archive!
redirect_to(:back)
end
I have moved the above to my concern called Foo and I've included Foo in my controller like this:
include Foo
The issue I have when moving these methods to a concern, is that the Model instance is not defined.
How do I generalize the "@bar" section of the code in my concern? This will enable me to use the concern for multiple Model instances including Baz. I tried using "self" but that references the Controller instance and not the Model instance.
@bardefined? You should have a method likedef find_bar @bar = Bar.find(params[:id]); endsomewhere.