0

I have a small app that Im trying to build I would like a user to be able to store a weight in the Weight model and a goal in the Goal model. While a user will be asked to enter a new weight in every week they will only be asked to enter a goal the first time they enter the app or any subsequent time where the weight is less than or equal to the current goal.

In the first iteration of this app and to get my head around the MVC and REST patterns i wish to simply redirect a user to the weight#new page where they will fill in the weight and then redirect the user to the goal#new page if the goal record is either blank(which it will be when they first sign up to the app) or on any other occasion where the current latest weight value is lower than or equal to the latest goal value in the most record.

My question is how would I go about setting up this logic in the controllers.

1 Answer 1

0

That should be easy. Something like this:

def some_action
  # ... do stuff
  if redirect_to_goal?
    redirect_to new_goal_path
  else
    redirect_to some_thing_else_path
  end
end

def redirect_to_goal?
   current_user.goals.empty? || any_other_condition      
end

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.