When I am doing rake db:migrate I am getting the below error.
rake aborted! NameError: uninitialized constant RailsAdmi
I checked an answer where It is said that there's some path set for rails admin in the routes file, I need to remove the same from it.
mount RailsAdmin::Engine => '/admin', as: 'rails_admin'
devise_for :users
resources :users
This is part of my route file. Even If I am removing this line, I am getting the same error.
In another answer It said to upgrade rails, I did that as well, but it gives same error.
Please help.
Related
I'm trying to use out-of-the-box spree routes, but I'm running up against an error that prevents me from migrating my database or precompiling my assets for Heroku:
rake aborted! ArgumentError: Invalid route name, already in use:
'account_link' You may have defined two routes with the same name
using the :as option, or you may be overriding a route already
defined by a resource with the same naming. For the latter, you can
restrict the routes created with resources as explained here:
https://guides.rubyonrails.org/routing.html#restricting-the-routes-created
My routes can be seen below, but I'm not doing any custom spree routes:
Rails.application.routes.draw do
# This line mounts Spree's routes at the root of your application.
# This means, any requests to URLs such as /products, will go to
# Spree::ProductsController.
# If you would like to change where this engine is mounted, simply change the
# :at option to something different.
#
# We ask that you don't use the :as option here, as Spree relies on it being
# the default of "spree".
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
# COSMETICS
get 'home/index'
root 'home#index'
get 'home/info'
get 'home/export'
get 'home/kits'
get 'kits/XR250_XR400'
get 'kits/XR600'
get 'kits/XR650L'
get 'kits/polaris_key_covers'
get 'kits/replacement'
get 'kits/rear_fenders_1'
get 'kits/rear_fenders_2'
get 'kits/graphics'
get 'other/xr400mx'
# PHOTOS
resources :photos
put "photos/:id/approve" => "photos#approve", as: "approve_photo"
put "photos/:id/unapprove" => "photos#unapprove", as: "unapprove_photo"
# CONTACT US
resources :contacts
put "contacts/:id/archive" => "contacts#archive", as: "archive_contact"
put "contacts/:id/unarchive" => "contacts#unarchive", as: "unarchive_contact"
get 'admin/blogs'
post 'uploader/image', to: 'uploader#image'
get 'admin/resources'
get 'admin/subcategories'
get 'admin/subscribers'
resources :blogs
resources :lead_magnets
resources :subscribers
resources :subcategories
mount Spree::Core::Engine, at: '/store', as: 'spree'
end
When I try to push to Heroku it shows the error is somewhere inside railties?
remote: Running: rake assets:precompile remote:
DEPRECATION WARNING: Single arity template handlers are deprecated.
Template handlers must remote: now accept two parameters, the
view object and the source for the view object. remote: Change:
remote: >> Coffee::Rails::TemplateHandler.call(template)
remote: To: remote: >>
Coffee::Rails::TemplateHandler.call(template, source) remote:
(called from at /tmp/build_3e42be0e/Rakefile:6) remote:
rake aborted! remote: ArgumentError: Invalid route name,
already in use: 'account_link' remote: You may have defined
two routes with the same name using the :as option, or you may be
overriding a route already defined by a resource with the same naming.
For the latter, you can restrict the routes created with resources
as explained here: remote:
https://guides.rubyonrails.org/routing.html#restricting-the-routes-created
remote:
/tmp/build_3e42be0e/vendor/bundle/ruby/2.6.0/gems/actionpack-6.0.3.2/lib/action_dispatch/routing/route_set.rb:578:in
`add_route'
I am seriously out of my depth here. Please help!
I'm running these spree-related gems:
gem 'spree', '~> 4.0'
gem 'spree_auth_devise', '~> 4.0.0'
gem 'spree_gateway', '~> 3.6'
My apps work fine in development mode on my localhost. But when i deploy my apps to Heroku i have an error like this :
/app/app/controllers/api/v1/Associations/associations_controller.rb:1:in `<top (required)>': uninitialized constant Api::V1::Associations (NameError)
I dont know whats wrong with my code. In my controller i have defined the class name like below :
class Api::V1::Associations::AssociationsController < Api::V1::ApiController
I already put this code on my application.rb but still no luck:
config.autoload_paths += Dir["#{Rails.root}/app/api/*"]
I have routes like below :
namespace :api do
namespace :v1, :defaults => {:format => :json} do
namespace :associations do
get "/index" => "associations#index"
post "/create" => "associations#create"
post "/join" => "associations#join"
resources :associations_groups
resources :group_joined_by_springs
resources :group_created_by_springs
end
end
end
Everything works fine in my local using development mode. I cannot figure out how to solve this errors. I hope someone could help me.
P/s : I already looked all the solution provided on this site.
Edit (Rake routes)
Below is my routes for Associations
api_v1_associations_index GET /api/v1/associations/index(.:format) api/v1/associations/associations#index {:format=>:json}
api_v1_associations_create POST /api/v1/associations/create(.:format) api/v1/associations/associations#create {:format=>:json}
api_v1_associations_join POST /api/v1/associations/join(.:format) api/v1/associations/associations#join {:format=>:json}
move your api directory in to the app directory and remove this setting from application.rb - config.autoload_paths += Dir["#{Rails.root}/app/api/*"]
All subdirectories of app in the application and engines present at boot time. For example, app/controllers. They do not need to be the default ones, any custom directories like app/workers belong automatically to autoload_paths.
From http://guides.rubyonrails.org
Pretty much as the title states, I have the following in my routes file:
root to: 'assets#index'
resources :assets do
member do
get :download
end
end
Yet my output for rake routes and visiting rails/info/routes are both simply:
Prefix Verb URI Pattern Controller#Action
root GET / assets#index
However the routes work fine in my views.
I also tried with bundle exec and I've updated to the latest version of bundle as some other posts suggested. It still works for my Rails 3 apps.
:assets is a reserved path in Rails. So you cannot really use it.
My environment:
Rails 3.2.8
Ruby 1.9.3p194
Fedora 16 x86_64
This problem seems specific to Rails Engines.
It seems that when using the HttpHelpers in a Rails Engine's routes file, I get "uninitialized constant Controller" when accessing a route via a browser. But, if I use a URL matcher in the Engine's routes file, it routes correctly.
Here's how I created a failing example:
$ rails plugin new my_engine --mountable
$ cd my_engine
$ rails g controller things index
$ rails s -p 3005
The controller generator uses the HttpHelpers#get method by default, so at this point the Rails Engine's config/routes.rb file looks like:
MyEngine::Engine.routes.draw do
get "things/index"
end
And, the test/dummy application's config/routes.rb file looks like:
Rails.application.routes.draw do
mount MyEngine::Engine => "/my_engine"
end
So, I should be able to hit http://locahost:3005/my_engine/things/index and see the Things#index view from the Engine. But, instead in the browser I see:
Routing Error
uninitialized constant ThingsController
If I manually change the Engine's config/routes.rb file to:
MyEngine::Engine.routes.draw do
#get "things/index"
match "things/index" => "things#index"
end
... and hit http://locahost:3005/my_engine/things/index, I see the correct Things#index view.
I noticed that when I use the HttpHelpers#get method in the Engine's config/routes.rb file, and run rake routes from the test/dummy directory, I see:
$ rake routes
my_engine /my_engine MyEngine::Engine
Routes for MyEngine::Engine:
things_index GET /things/index(.:format) things#index
But, if I change the Engine's config/routes.rb file to use the URL matcher method, I see:
$ rake routes
my_engine /my_engine MyEngine::Engine
Routes for MyEngine::Engine:
things_index /things/index(.:format) my_engine/things#index
Notice that when using the URL matcher, the controller and action are correctly namespaced under the engine. While, when using the HttpHelpers#get, the controller and action seem to be non-namespaced.
So, my question: Am I doing something wrong here? Or, is this a bug?
Note: I searched the rails issues and didn't see anything directly related to this. Though I did see several other engine and routing issues.
I have the following in my routes.rb file for Rails 3:
13 namespace :user do
14 root :to => "users#profile"
15 end
I get this error on heroku:
ActionController::RoutingError (uninitialized constant User::UsersController):
I already restarted the application.
I am doing this because I am using devise and this is what it says on the wiki:
https://github.com/plataformatec/devise/wiki/How-To:-Redirect-to-a-specific-page-on-successful-sign-in
The problem is that Rails is expecting there to be a controller within a module called Users because that's what namespace :user infers. Perhaps you meant to use scope instead of namespace?
scope :path => "user" do
root :to => "users#profile"
end
Note: in this situation if you've only got one route it would not be wise to use scope, but if you've got multiple ones with the /user prefix then it would be fine to. If you only had one, I would do this instead:
get '/user', :to => "users#profile"
Heroku environments run in production mode. When you run locally, you run in development mode, which accounts for at least one difference. Try this instead:
RAILS_ENV=production bundle exec rails s
and see if you notice the same error.