Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting RuntimeError: "In order to use #url_for, you must include routing helpers explicitly" when I've already included them

Inside a controller I've tried to run this code for when users that are already logged in stumble across the sign up page

def index
  if current_user
    redirect_to homebase_url #should provide url to home for logged in users
  end
end

I've done what the rails error message said and have added: include Rails.application.routes.url_helpers to the containing controller class. Still getting this error though. Definitely do not want to hardcode URLs into there for legacy purposes. Thanks

like image 364
boulder_ruby Avatar asked Sep 17 '25 06:09

boulder_ruby


1 Answers

Remove the include Rails.application.routes.url_helpers declaration, it's not needed unless it's in something like a helper. Routes are included in controllers by default. Including it in a model or controller/initializer (routes are loaded before initializers) is against MVC architecture and might cause unwanted behaviour.

like image 200
Shannon Avatar answered Sep 19 '25 19:09

Shannon