Uninitialized constant Admin::Admin - ruby-on-rails

Using Ruby: 2.3.1p112 and Rails: 3.2.12
I'm trying call a demo method in my controller. So, in my _form.html.erb I have:
<%= link_to 'Demo', "/admin/clinics/"+#clinic.id.to_s+"/demo" %>
In my routes.rb:
match "/admin" => "admin#index", :as => :admin
namespace :admin do
resources :admin_users
resources :health_plan_tables
resources :health_aid_tables
resources :clients
resources :clinics
resources :specialties
resources :qualifications
resources :profissionals
resources :addresses
resources :documents
resources :banners
root :to => 'banners#index'
get 'logout' => 'devise/sessions#destroy'
get 'clinics/:id/demo', to: 'admin/clinics#demo', as: 'demo'
end
My clinics_controller.rb is inside the folder controllers/admin, and I just have:
def demo
print "hello"
end
So, when I click on link, error message appears Uninitialized constant Admin::Admin.
Any ideia how to fix it?

Since you are already defining your demo route inside a namespace there is no need to specify admin/clinics#demo, just clinics#demo will be necessary:
namespace :admin do
resources :admin_users
resources :health_plan_tables
resources :health_aid_tables
resources :clients
resources :clinics
resources :specialties
resources :qualifications
resources :profissionals
resources :addresses
resources :documents
resources :banners
root :to => 'banners#index'
get 'logout' => 'devise/sessions#destroy'
get 'clinics/:id/demo', to: 'clinics#demo', as: 'demo'
end

According to the error log you're looking for a controller namespaced under admin/admin/clinics (it says that in the controller part of the params).
Change the bottom route to not include admin (it's already namespaced and you're effectively namespacing it twice):
get 'clinics/:id/demo', to: 'clinics#demo', as: 'demo'
This will route to the correct controller, admin/clinics, instead of admin/admin/clinics

Related

Rails 6 routing for admin section with arguments in the URL

how can I organize routing for /admin section with arguments before the "/admin".
For example, /:country_id/:lang_id/admin
Path example, /ukraine/english/admin
I have tried:
scope path:"/:country_id/:lang_id/admin", :as => "admin" do
resources :cities, controller:'admin/cities'
but "admin_cities_path" create wrong internal links
<%= link_to city.title, admin_cities_path(city.id) %>
Rails returns the following UR:: /1/english/admin/cities
instead of:
/ukraine/english/admin/cities/1
Routes.rb
Rails.application.routes.draw do
devise_for :users
devise_for :views
get 'home/index', to: 'application#index'
root to: "home#index"
get '/:id/:lang_id/admin', to: 'admin/admin#index'
get '/admin', to: 'admin/admin#index'
scope path:"/:country_id/:lang_id/admin", :as => "admin" do
#namespace :admin do
resources :cities, controller:'admin/cities'
resources :comments do
member do
get 'approve'
get 'disapprove'
end
end
resources :countries
resources :industries
resources :products
resources :languages
resources :categories
resources :companies
end
#root "articles#index"
#get "/admin/countries", to: "countries#index"# For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html
# resources :countries do
# resources :languages
# end
resources :countries
get '/countries/', to: 'countries#index'
get '/languages/', to: 'languages#index'
get '/:id/', to: 'countries#show', as: 'localized_country'
get '/:id/:lang_id/', to: 'languages#show', as: 'localized_language'
#get '/:id/:lang_id/:category_id/', to: 'categories#show', as: 'localized_category'
get '/:id/:lang_id/:industry_id/', to: 'industries#show', as: 'localized_industry'
get '/:id/:lang_id/:industry_id/:category_id/', to: 'categories#show', as: 'localized_category'
get '/:id/:lang_id/:industry_id/:category_id/:city_id/', to: 'cities#show', as: 'localized_city'
get '/:id/:lang_id/:industry_id/:category_id/product/:product_id/', to: 'products#show', as: 'localized_product'
resources :languages, param: :land_id
resources :products
resources :industries
resources :categories, param: :category_id
resources :products do
resources :comments
end
end
I am just guessing what you want if its not satisfied then pls comments some code or more information to solve it.
resources :country, path: '' do
resources :language, path: '' do
namespace "admin" do
resource :cities
end
end
end
The above code will reporduce the path in following format.
new_country_language_admin_cities GET /:country_id/:language_id/admin/cities/new(.:format) admin/cities#new
edit_country_language_admin_cities GET /:country_id/:language_id/admin/cities/edit(.:format) admin/cities#edit
and so on...

Cannot logout of rails application devise gives error Could not find devise mapping for path "/tuners/sign_out

I have this issue when loging out of devise:
Could not find devise mapping for path "/tuners/sign_out". This may happen for two reasons: 1) You forgot to wrap your route inside the scope block. For example: devise_scope :user do get "/some/route" => "some_devise_controller" end 2) You are testing a Devise controller bypassing the router. If so, you can explicitly tell Devise which mapping to use: #request.env["devise.mapping"] = Devise.mappings[:user]
My routes file
Rails.application.routes.draw do
devise_for :tuners
get '/tuners/sign_out' => 'devise/sessions#destroy'
resources :hardy_pianos
devise_for :admins
resources :images
resources :entries
resources :models
get '/clients/mail_room' => 'clients#mail_room'
get '/clients/mail' => 'clients#mail'
#list of clients to reschedule
get '/clients/book_again' => 'clients#book_again'
# current upcoming jobs
get '/clients/current' => 'clients#current'
# reports
get '/clients/reports' => 'clients#reports'
resources :clients
seems_rateable
post '/rate' => 'rater#create', :as => 'rate'
resources :technicians
resources :members
resources :admins
resources :tuners
get 'tuners/tuners_pianos'
get 'pianos/tuners_pianos'
resources :tuners
resources :journals
resources :expenses
resources :interests
resources :purchases
resources :contacteds
resources :pianos
get '/pianos/work_needed' => 'pianos#work_needed'
get '/invoices/work_needed' => 'invoices#work_needed'
resources :invoices
resources :pages
#devise_for :installs
resources :prosperities
get '/finances/taxes' => 'finances#taxes'
resources :posts
get '/tunings/current' => 'tunings#current' # or match for older Rails versio
get '/tunings/bookagain' => 'tunings#bookagain' # or match for older Rails version
get '/tunings/bookagain12' => 'tunings#bookagain12'
get '/tunings/reports' => 'tunings#reports'
get '/tunings/information' => 'tunings#information'
resources :tunings
root 'pages#index'
get '/' => 'tunings#current'
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
end
Can anyone help me understand what the issue is here with this? I'm kind of stuck with this and have googled for a while but left it on the back burner. Thanks in advance.
Replace the line:
get '/tuners/sign_out' => 'devise/sessions#destroy'
with
delete 'sign_out', to: 'devise/sessions#destroy'
or can you try this this. watch the order of lines.:
Rails.application.routes.draw do
devise_scope :tuners do
get "sign_out", to: "devise/sessions#destroy"
end
devise_for :tuners

Rails: Can't use member outside resource(s) scope (ArgumentError)

I have been upgrading to Rails 4, and after running command "rspec ." I am getting the following error:
/Users/lexi87/.rvm/gems/ruby-2.0.0-p0/gems/actionpack-4.0.0.rc1/lib/action_dispatch/routing/mapper.rb:1297:in `member': can't use member outside resource(s) scope (ArgumentError)
I have changed my route file a little and still no work. If anyone has run into a similar issue and has a fix please share with me. Thanks in advance!
Dating::Application.routes.draw do
get 'signup' => 'users#new'
get 'login' => 'sessions#new'
get 'logout' => 'sessions#destroy'
get 'edit' => 'users#edit'
get "/profile/:id" => "users#show"
get "profile/:id/settings" => 'users#edit'
get 'settings/:id' => 'users#settings'
resources :sessions
resources :password_resets
resources :galleries
resources :photos
resources :searches
resources :questions do
resources :answers, only: [:new, :create]
end
resources :users do
member do
get :settings
end
end
root to: 'galleries#index'
resources :users do |user|
resources :messages do
collection do
post 'delete_multiple'
get 'settings', on: :member
end
end
end
I think the problem is here:
resources :messages do
collection do
post 'delete_multiple'
get 'settings', on: :member # <--here
end
end
You can't define a member inside the collection, you should move it up to the resources block, like this:
resources :messages do
collection do
post 'delete_multiple'
end
get 'settings', on: :member
end
Remember that a member route will require an ID, because it acts on a member. A collection route doesn't because it acts on a collection of objects.
So you can't use both at the same time.

Rails routes error. No route matches [POST] "/sessions/new"

Hello im doing tutorial from Rails Book and get into some troubles.
While im trying to log in with my username and password im getting the following error:
Routing Error
No route matches [POST] "/sessions/new"
Try running rake routes for more information on available routes.
This is my route file config.
ZomfgShop::Application.routes.draw do
get "admin/index"
get "sessions/new"
get "sessions/create"
get "sessions/destroy"
resources :users
resources :orders
resources :line_items
resources :carts
get "store/index"
resources :products do
get :who_bought, on: :member
end
resources :products
root to: 'store#index', as: 'store'
resources :line_items do
#member do
# post 'decrement'
#end
post 'decrement', on: :member
end
get 'admin' => 'admin#index'
controller :sessions do
get 'login' => :new
post 'login' => :create
delete 'logout' => :destroy
end
You have controller instead of resources for the :sessions routes.
resources :sessions do
get 'login' => :new
post 'login' => :create
delete 'logout' => :destroy
end
Try replacing
get "sessions/new"
get "sessions/create"
get "sessions/destroy"
with
resources :sessions
make sure you have a views/sessions/new.html.erb file (under views/devise/ if using devise)
and make sure you have this in sessions_controller.rb if you aren't using Devise
def new
end
def create
end
def destroy
end
Thank you guys, changed my routes.rb file to this and my routing fine is working fine once again!
ZomfgShop::Application.routes.draw do
get 'admin' => 'admin#index'
controller :sessions do
get 'login' => :new
post 'login' => :create
delete 'logout' => :destroy
end
scope '(:locale)' do
resources :users
resources :orders
resources :line_items
resources :carts
get "store/index"
resources :products do
get :who_bought, on: :member
end
root to: 'store#index', as: 'store'
end
resources :line_items do
#member do
# post 'decrement'
#end
post 'decrement', on: :member
end

How to define a route in Ruby on Rails

I'm trying to define a route in routes.rb and I can't do anything from this Ruby on Rails routing guide that will let this error pass.
No route matches {:controller=>"devise/home"}
Here's my routes.rb source.
SchoolCMS::Application.routes.draw do
root :to => "home#index"
devise_for :teachers, :admin
resources :home, :only => :index
resources :admin, :only => :index
resources :events do
resources :event
end
resources :posts do
resources :comments
end
end
Just to be safe I would remove devise_for :teachers, :admin and split it so that it is
devise_for :teachers
devise_for :admin
I'm not sure you can specify multiple devises the way you use it, see if this fixes your error.
Also try to use path helpers were possible so instead of doing <%= link_to 'Home', :controller => 'home' %> make it <%= link_to 'Home', homes_path %> but make sure you define your home as resource :home, :only => :show since it's a singular resource.

Resources