Devise user_root_path gets 404'd in production, but not dev?

strange, I know, but using user_root_path in production doesn't work. When I click on the link myapp.com/user , I get page 404.

There is no scythe in the log file, but an unsuccessful 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 unified constant is to enable rails c and enter the constant into the console. Here's what happens:

 ruby-1.9.2-p136 :005 > User::UsersController (irb):5: warning: toplevel constant UsersController referenced by User::UsersController => UsersController 

Now, some digging has discovered that this level warning could be related to it. But the magazine talks about bubbles.

So, I changed the route file:

  devise_for :users namespace :user do root :to => "users#index" end resources :subdomains match '/user' => 'users#index' 

in

 devise_for :users namespace :user do root :to => "subdomains#index" end resources :subdomains match '/user' => 'users#index', :controller => :users 

The idea was that perhaps the production environment did not like the user index #, so I changed it to the index of subdomains #. I can get / subdomains without problems. so the actual page will show this is a route that is being washed ... any thoughts?

setup: rails 3.0.3, develop 1.1.5 (and 1.1.3 was updated, same problem)

+4
source share
3 answers

I used

 devise_for :users do match 'user' => "users#index", :as => :user_root, :constraints => { :domain => SITE_DOMAIN} end 

In each of the development.rb or production.rb files, you will have the SITE_DOMAIN constant, for example:

 ::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 need subdomains, so this worked for me.

The wiki developer did not work for me. As soon as I have time, I will update it or send a ticket, but this is just Google juice for those who need it.

+2
source

If you use namespacing for your routes, you will also need to register your controllers.

Move the / users _controller.rb controllers to the / user / users _controller.rb controllers and edit them to add to the module:

 class User::UsersController < ApplicationController end 

But I assume that you really do not want to use the namespace in the route.

0
source

I had the same issue with / user giving 404 in production. Here is the solution, as a result of which I decided that it’s easier than messing around with the routes. In the 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?

0
source

Source: https://habr.com/ru/post/1336219/


All Articles