For my rails 3 app I have a route setup as follows
namespace :user do
root :to => "reading_schedules#index"
end
This is what my "rake routes" shows
user_root /user(.:format) {:controller=>"user/reading_schedules", :action=> "index }
Everything works fine on my localmachine. But as soon as I push the site up to Heroku and login I get the following error in my logs
ActionController::RoutingError (uninitialized constant User::ReadingSchedulesController):
If I navigate to the root of the site everything else works fine. But this one url doesn't work. The url it's trying to hit is website/user but like I said, it works fine on my localmachine.
EDIT:
Here's the rest of my routes file
devise_for :users, :path => 'accounts'
root :to => "home#landing"
namespace :user do
root :to => "reading_schedules#index"
end
resources :users do
resources :reading_schedules
member do
get :change_password
post :change_password
end
end
resources :reading_schedules do
member do
get :recalculate
end
end
I found this question first in looking for an answer to the same issue. For any future searchers, check out this link.
For me, it was a combination of the last two answers in this post (adapted for my controllers of course.)
Also of note, this corrected the issue without having to reset the database.
ActionController::RoutingError (uninitialized constant User::UsersController) in heroku (but everything works in local)
Probably not the answer you are looking for but
heroku rake db:reset
solved the problem for me. I didn't have any critical data in the
db so it was not a problem.
Related
Hi I'm trying to deploy an app made with help of "Agile web development by S.Ruby" and I always get the same error - The page you were looking for doesn't exist.
You may have mistyped the address or the page may have moved.
I've already tried to migrate my DB on Heroku - that wasn't the case.I think something is wrong with routes.rb file, but I can't understand what is incorrect exactly,please help me to solve this problem
Here is my routes.rb file:
Depot::Application.routes.draw do
get 'admin' => 'admin#index'
controller :sessions do
get 'login' => :new
post 'login' => :create
delete 'logout' => :destroy
end
get "sessions/create"
get "sessions/destroy"
resources :users
resources :products do
get :who_bought, on: :member
end
scope '(:locale)' do
resources :orders
resources :line_items
resources :carts
root 'store#index', as: 'store', via: :all
end
end
As Michal correctly points out you miss the root path. You have defined a route inside the scope you use to get to the different locales, but not a global root. This is not a Heroku problem, it won't work on your local server either.
So, http://your_server.com/en will work, but http://your_server.com will not.
You need to add a root path outside all scopes, like so:
root 'store#index'
You will have to set a default locale or something like that. You can leave the other root directive inside the scope, as you have named it explicitly (with as: 'store') there won't be any conflict.
On my local machine, when I authenticate at http://subdomain.myapp.dev (using the Pow server), I am properly redirected to the index page.
When logging into the production domain http://subdomain.myapp.com (hosted on Heroku), I am also able to properly authenticate; however, Heroku is not redirecting to the index page. After submitting the necessary credentials, I receive the 'Signed in successfully' notification but remain on the sign in page.
rake routes and heroku run rake routes return identical routing schemes. I've also listed the contents of my routes.rb file below
Example::Application.routes.draw do
devise_scope :user do
authenticated :user do
root :to => 'admin/servers#index'
end
unauthenticated :user do
root :to => 'devise/sessions#new'
end
end
resources :server_imports
resources :servers
devise_for :users
ActiveAdmin.routes(self)
end
Below are the logs after entering the credentials for signing in:
2013-10-12T01:59:32.110046+00:00 app[web.1]: Started POST "/users/sign_in"
2013-10-12T01:59:32.529842+00:00 app[web.1]: Started GET "/"
And here is the first line from heroku run rake routes
root GET / admin/servers#index
As mentioned above, I still get re-routed to the sign in page after successful authentication. I am confused why this problem is only experienced on Heroku and not on my local machine
Why not do something like this:
def after_sign_in_path_for(resource)
admin_servers_index_path
end
See: https://github.com/plataformatec/devise/wiki/How-To%3A-Redirect-to-a-specific-page-on-successful-sign-in-and-sign-out
I'm new to ruby on rails, and I'm having trouble getting up to speed. I've set up devise for user authentication, and everything seemed to be going well. Until I tried to get routes set up
Basically, I've deleted my /public/index.html, and I've set a new default route. Here's my /config/routes.rb
MyApp::Application.routes.draw do
authenticated :user do
root :to => 'home#index'
end
root :to => "home#index"
devise_for :users
end
Okay, so that seems simple enough. I generated a home controller/view. My index.html.erb is just the default. My controller is also blank.
When I run rake routes, I can see the route to the root.
root / home#index
root / home#index
So this seems like a go! But...It's not. I get an error when I try and open my index
No route matches [GET] "/"
I don't feel like the details of my server should be significant, but it's nginx. I can post my server configuration if anyone thinks it's important.
Blargh. I'm an idiot. The server configuration I though wouldn't matter was the problem. I had edited my nginx settings, but I left the default in Unicorn. I never noticed before now, since the /public/index.html in both the unnecessary app and my app were the same. Thanks for all the help though.
You should be add resources :homes
MyApp::Application.routes.draw do
resources :homes
root :to => "home#index"
devise_for :users
end
weird, i know but using user_root_path in production does not work. When i click on the link myapp.com/user i get a 404 page.
The log file doesn't show spit but a failed attempt:
Started GET "/user" for 123.125.146.23 at 2011-01-19 19:40:45 +0000
ActionController::RoutingError (uninitialized constant User::UsersController):
Now the only way to see something about this unitialized constant is to turn on rails c and type the constant into the console. Here is what happens:
ruby-1.9.2-p136 :005 > User::UsersController
(irb):5: warning: toplevel constant UsersController referenced by User::UsersController
=> UsersController
Now some digging found that this toplevel warning could be messing with it. But the log says bubkiss.
So i changed the route file from:
devise_for :users
namespace :user do
root :to => "users#index"
end
resources :subdomains
match '/user' => 'users#index'
to:
devise_for :users
namespace :user do
root :to => "subdomains#index"
end
resources :subdomains
match '/user' => 'users#index', :controller => :users
The thought was that maybe production environment did not like a user#index... so i changed it to subdomains#index. I can get /subdomains no problem. so the actual page will show, it's the route that is fudged... any thoughts?
setup: rails 3.0.3, devise 1.1.5 (and was 1.1.3 upgraded, same problem)
I used
devise_for :users do
match 'user' => "users#index", :as => :user_root, :constraints => { :domain => SITE_DOMAIN}
end
In each of your development.rb or production.rb files you would have a SITE_DOMAIN constant so like:
::SITE_DOMAIN = "lvh.me"
#in development.rb I was using subdomains with the helpful lvh.me google it.
or in production.rb
::SITE_DOMAIN = "mydomain.com"
Again i needed subdomains, so this worked for me.
The devise wiki did not work for me. Once i have time i will update that too, or submit a ticket, but this is just google juice for those that need it.
If you are namespacing your routes, you need to namespace your controllers as well.
Move controllers/users_controller.rb to controllers/user/users_controller.rb and edit it to add in the module:
class User::UsersController < ApplicationController
end
But my guess is you aren't actually meaning to use namespace in the route.
I had the same problem with /user giving a 404 in production. Here is the solution I ended up with which I think is simpler than messing with the routes. In ApplicationController put:
def after_sign_in_path_for(resource)
stored_location_for(:user) || landing_welcome_path
end
Can someone explain how the environment affects routing in rails 3?
I have an app that has the following in the routes file:
namespace "admin" do
# ADMINISTRATIVE ROUTES ONLY
root :to => 'home#index'
resources :comments do
member do
get :approve
get :reject
end
end
resources :users do
member do
get :block
get :unblock
end
end
end
When browing to /admin locally, I am greeted by the appropriate page.
On the same URL on the heroku version I get a 404. The route shows
correctly in 'heroku rake routes'
Logs are showing:
ActionController::RoutingError (wrong constant name Admin/
homeController):
/disk1/home/slugs/196384_c95a9e3_4463/mnt/.bundle/gems/gems/
activesupport-3.0.0.beta4/lib/active_support/inflector/methods.rb:
103:in `const_defined?'
Any ideas?
It transpires that this is an issue with the right_aws gem that we had in our Gemfile.
It looks like it's finding a lowercase "homeController" class, but I don't understand why. Check your file to make sure you've named your class correctly?
Looks like a bug in the ActiveSupport beta. Are you running exactly the same rails version?