I am starting to move rather large nested if logic in a view to a decorator and trying to simplify my routes and controllers. I’m curious of a best way to build/launch a modal. To keep it simple, let’s say I have an attribute “first_post” on user so I can give some advice the first time the user creates a new post. I don’t want to have a hard-coded hidden modal in the view all the time that just changes css to display.
To get around that I currently (pre-decorator) have a custom route “check_user_attribute” which has an action on the user controller to do if/then, responding as ajax call from the view. I would much rather contain this bit of logic in one place instead of a new controller action (“check_attribute”) and route.
What I would like to happen is user clicks a button generated from the decorator to a create path, which checks to see if user has an attribute, if so render the warning modal, if not proceed to create action. Ultimately I’m trying to move this all to a new user_manager class, but trying to move in small steps.
Would simply using the user decorator to decide whether the users first post is true and calling it from the view work? something like ‘first_post?’ in the decorator that simply calls ‘render first_post_advice’ partial?