I'm having trouble with controllers and routes in ruby on rails. I cant figure out what i've done wrong. I appreciate help! I guess its a pleural issue however i'm only a begginer.
Errors says Routing error | uninitialized constant App::SettingsController
Controller:
class App::SettingsController < App::BaseController
def index
end
end
Routes:
Rails.application.routes.draw do
get 'calendar/index'
root to: 'visitors#index'
devise_for :users, controllers: {
sessions: 'users/sessions',
registrations: 'users/registrations',
passwords: 'users/passwords',
invitations: 'users/invitations',
}
namespace :app do
get 'dashboard' => 'dashboards#index', as: :dashboards
get 'setting' => 'settings#index', as: :settings
get 'report' => 'reports#index', as: :reports
resources :residents
resources :contacts
resources :users do
collection do
get :profile
end
end
end
namespace :admin do
resources :users
end
end
View:
app/views/app/settings
app/views/app/settings/index.html.erb
Wrong file name setting.rb should be settings_controller.rb
Related
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 am having trouble getting my app to run in production via Heroku. It is a fully working application in development.
I researched this question on SO but many of the solutions were because of a duplicate devise_for in their routes.rb. My app does not have this issue, and I have had difficulty in finding out where this duplication is occurring.
This is the full error message:
/app/vendor/bundle/ruby/2.0.0/gems/actionpack-4.2.4/lib/action_dispatch/routing/route_set.rb:557:in `add_route': Invalid route name, already in use: 'new_user_session' (ArgumentError)
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:
http://guides.rubyonrails.org/routing.html#restricting-the-routes-created
This is my current routes.rb file:
Rails.application.routes.draw do
devise_for :users, :controllers => { registrations: 'registrations' }
get 'items/create'
get 'welcome/index'
get 'about' => 'welcome#about'
get 'brandon' => 'welcome#brandon'
root 'welcome#index'
resources :users, only: [:index, :show] do
resources :items
end
end
I have updated my gems, dropped the database and re-migrated it to no effect.
#config/routes.rb
Rails.application.routes.draw do
resources :items, only: [:new, :create], path_names: { new: "create" }
resources :welcome, path: "", only: :index do #-> url.com/
collection do
get :about #-> url.com/about
get :brandon #-> url.com/brandon
end
end
resources :users, only: [:index, :show] do #-> there may be a conflict with "/users/" as devise also uses "/users/" path
resources :items #-> url.com/users/:user_id/items
end
devise_for :users, controllers: { registrations: 'registrations' }
root "welcome#index"
end
I'll delete this if it doesn't work; you either have a problem with the "naked" declarations you're making (always try and scope your routes around resources), or you have a conflicting file in your production environment.
I went into similar situation.
The use of as option of devise_for solved for me.
devise_for :users, as: "unique_prefix", :controllers => { registrations: 'registrations' }
I have put login and signup in one page and every thing works fine except when I encounter errors. Then the page redirects to their default pages and show errors there. In my case the login redirects me to the default domain.com/users/sign_in , but signup redirects me to domain.com/users.
routes.rb
Rails.application.routes.draw do
root 'visitor#index'
namespace :admin do
# get "/stats" => "stats#stats"
devise_scope :admin_user do
get '/stats/:scope' => 'stats#stats', as: :admin_stats
end
end
devise_for :admin_users, ActiveAdmin::Devise.config
ActiveAdmin.routes(self)
namespace :client do
get 'dashboard' => 'dashboard#index', as: 'dashboard'
# resources :verification, only: [:create, :index, :destroy]
get 'verification' => 'verification#index', as: 'verification'
match 'verification' => 'verification#upload', as: 'verification_upload', via: [:post, :patch]
end
devise_for :users, class_name: 'FormUser', controllers: { omniauth_callbacks: 'omniauth_callbacks', registrations: 'registrations' }
# devise_scope :user do
# root to: 'devise/registrations#new'
# end
end
you can use a CustomFailure class to control where the redirect goes if Devise fails to authenticate.
It's explained at this wiki page...
https://github.com/plataformatec/devise/wiki/How-To:-Redirect-to-a-specific-page-when-the-user-can-not-be-authenticated
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.
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