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
Related
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
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
I'm getting this error when I try to logout an user. I checked many posts of this same error but no one solved my error, I hope you can help me.
The error is as follows:
ActiveRecord::RecordNotFound in UsersController#destroy
Couldn't find User with 'id'=sign_out
The following is my code:
users_controller.rb
def destroy
#user.destroy
respond_to do |format|
format.html { redirect_to unauthenticated_root_path }
format.json { head :no_content }
end
end
private
private
# Use callbacks to share common setup or constraints between actions.
def set_user
#user = User.find(params[:id])
end
view/users/index.html.erb
<li>
<%= link_to "Logout", destroy_user_session_path, :method => :delete %>
</li>
routes.rb
Rails.application.routes.draw do
get 'admin/index'
resources :contacts
resources :afections
resources :injuries
resources :allergies
resources :trainers
resources :idusuarios
resources :diseases
resources :weights
resources :diets
resources :exercices
resources :profiles
resources :users
devise_for :users
get '/users/sign_out' => 'devise/sessions#destroy'
devise_scope :user do
authenticated :user do
root 'pagina#index', as: :authenticated_root
end
unauthenticated do
root 'devise/sessions#new', as: :unauthenticated_root
end
end
end
move get '/users/sign_out' => 'devise/sessions#destroy' above resources :users in your routes. Routes are given priority in terms of their order in the routes file.
When you use resources :users in your routes, you have this routes:
/users
/users/:id
/users/:id/edit
and ...
So when /users/sign_out is called, , thinks the sign_out is an ID.
so change /users/sign_out to /user/sign_out for example.
BUT
if you want customize your session paths, you can do this:
customize your session paths:
as :user do
get 'user/signin' => 'devise/sessions#new', :as => :new_user_session
post 'user/signin' => 'devise/sessions#create', :as => :user_session
delete 'user/signout' => 'devise/sessions#destroy', :as => :destroy_user_session, via: [:delete, :get]
end
and skip session in devise:
devise_for :users, :skip => [:sessions]
if you want user registration, you must skip it in devise and then can use user scaffold:
as :user do
get 'user/signin' => 'devise/sessions#new', :as => :new_user_session
post 'user/signin' => 'devise/sessions#create', :as => :user_session
delete 'user/signout' => 'devise/sessions#destroy', :as => :destroy_user_session, via: [:delete, :get]
end
scope "admin" do
resources :users
devise_for :users, :skip => [:sessions, :registrations]
end
try to install active admin , but i encounter this error "Invalid route name, already in use: 'admin_root'"
so after i research stackoverflow . i found some answers ,trying to apply them to my case but it's not working . here's my routes.rb. im confused which routes should i delete to fix the prob.i don't have any admin routes . it's a little confusing.
devise_for :admin_users, ActiveAdmin::Devise.config
ActiveAdmin.routes(self)
resources :activities, only: [:index, :destroy]
get "relationships/create"
get "relationships/destroy"
get "users/show"
# You can have the root of your site routed with "root"
root 'videos#index'
get 'home', :to => "pages#home", :as => :home
get 'login', :to => "pages#login", :as => :login
get 'about', :to => "pages#about", :as => :about
get 'browse', :to => "pages#browse", :as => :browse
get 'recent', :to => "videos#recent", :as => :recent
devise_for :users
ActiveAdmin.routes(self)
get 'users/:id' => 'users#show', as: :user
resources :relationships, only: [:create, :destroy]
resources :user_friendships
resources :videos
resources :hearts, only: :create
resources :playlists
resources :users do
resources :playlists do
resources :videos
end
member do
get :following, :followers
end
end
You are trying to load the ActiveAdmin routes twice. You have this line twice:
ActiveAdmin.routes(self)
Remove one of those instances and you should be good to go.
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.