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
Im trying to sent people to a different site with redirect
private
def must_be_over_13
if birthday && birthday > 13.years.ago
redirect_to under_13_landing_page_path ``
end
end
I defined under_13_landing_page
controller/student controller
def under_13_landing_page
end
views/students
I made the redirect page
under_13_landing_page.html
config/routes.rb
I told it to redirect it to the landing page
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
andredirection
are Controller's responsibility NOT Model's. You should not be redirecting in the Modelapp/models/student.rb
. This is the reason of the code failure as Model doesn't have access to the route helper methods such asunder_13_landing_page_path
in your case.I would suggest you to return a
boolean
value fromStudent#must_be_over_13
method which you can then check in the concerned controller andredirect
appropriately.