I'm having a problem with redirecting my website to a different page, if the person is younger then a certain age. Either, I need more coffee or I've lost it, I can't seem to see what I did wrong. Thanks so much.
app/models/student.rb
private
def must_be_over_13
if birthday && birthday > 13.years.ago
redirect_to under_13_landing_page_path ``
end
end
controller/student controller
def under_13_landing_page
end
views/students
under_13_landing_page.html
config/routes.rb
get "games_for_kids", to: "students#under_13_landing_page", as: 'under_13_landing_page'
THE ERROR**undefined local variable or method `under_13_landing_page_path' for #**
rendering
and redirection
are Controller's responsibility NOT Model's. You should not be redirecting in the Model app/models/student.rb
. This is the reason of the code failure as Model doesn't have access to the route helper methods such as under_13_landing_page_path
in your case.
I would suggest you to return a boolean
value from Student#must_be_over_13
method which you can then check in the concerned controller and redirect
appropriately.