Issue with configuring active admin - ruby-on-rails

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.

Related

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

How to use concerns in routes ruby on rails

I have resources :subjects in my routes which I wants to use as optional routes by using concern.
The idea is to use DRY approach so I do not need to re-write routes lines for other case in which I do not need resources :subjects.
The links are like below and it is clear I have no subject_id in 2nd case as I do not need it:
http://localhost:3000/teacher/katherine-fleming/subjects/3/lesson_plans/3
and
http://localhost:3000/teacher/carmel-cynthia/lesson_plans/3
Right now, it stops working for both cases and saying:
ActionController::RoutingError (No route matches [GET] "/teacher
/katherine-fleming/subjects/3/lesson_plans/3"):
ActionController::RoutingError (No route matches [GET] "/teacher/carmel-
cynthia/lesson_plans/68"):
My routes for case 1 are:
resources :subjects do
concern :lesson_plans, :except => [:index] do
resources :lesson_plan_registrations
resources :comments, only: [:new, :create, :destroy]
end
end
I am trying to make them working using below code but its not working as expected.
resources :lesson_plans, concerns: :lesson_plans
What's working right now is:
resources :subjects do
resources :lesson_plans, :except => [:index] do
resources :lesson_plan_registrations
resources :comments, only: [:new, :create, :destroy]
end
end
resources :lesson_plans, :except => [:index] do
resources :lesson_plan_registrations
resources :comments, only: [:new, :create, :destroy]
end
But its something to re-write the whole code again for the case in which I do not need resources :subjects.
I want to use DRY approach so it will work for both cases.
Here are full routes.rb file:
Rails.application.routes.draw do
root 'welcome#index'
devise_for :users, controllers: {sessions: 'sessions', registrations: 'registrations', :omniauth_callbacks => 'omniauth_callbacks'}
resources :requested_schools, only: [:new, :create]
resources :tags, only: :index
resources :specializations, only: :index
resources :search, only: :index
get '/fetch_schools' => 'search#fetch_schools'
get '/fetch_subjects' => 'search#fetch_subjects'
resources :search_results do
collection do
get '/lesson_plan' => 'search_results#lesson_plan', as: :lesson_plan
get '/video' => 'search_results#video', as: :video
get '/document' => 'search_results#document', as: :document
get '/note' => 'search_results#note', as: :note
end
end
namespace :admin do
root 'dashboard#index'
get 'login' => 'sessions#new', as: :login
resources :dashboard, only: [:index]
resources :requested_schools, only: [:index, :edit, :edit, :show, :destroy] do
member do
get :accept_request
get :decline_request
get 'view_files' => 'requested_schools#view_files', as: :view_files
get 'imported_data' => 'requested_schools#imported_data', as: :imported_data
end
end
resource :users, :except => [:show, :index, :new, :create] do
member do
get :change_password
patch :update_password
end
end
end
namespace :school do
root 'dashboard#index'
resources :dashboard, :path => '/', only: [:index]
resources :departments do
resources :subjects
end
resources :class_rooms do
resources :class_room_subjects
resources :class_room_schedules
resources :class_room_registrations do
collection do
post "/student_registration" => "class_room_registrations#student_registration", as: :student_registration
end
end
end
get '/fetch_subject_teachers' => 'class_room_subjects#fetch_subject_teachers', as: :fetch_subject_teachers
resources :schools, :path => '/', only: [:index, :edit, :show, :destroy, :update] do
collection do
get :change_password
patch :update_password
get :edit_profile
patch :update_profile
get :listing
get :view_ids
match "/upload_ids" => "schools#upload_ids", via: [:get, :post]
get :autocomplete_school_name
get '/view_lesson_plan/:id' => "schools#view_lesson_plan", as: :view_lesson_plan
end
member do
get :students
get :teachers
get :lesson_plans
match '/class_rooms' => "class_rooms#index", via: [:get, :post]
end
end
end
resources :friend_requests do
member do
get '/send_friend_request/:type' => "friend_requests#send_friend_request", as: :send_friend_request
get '/decline_friend_request/:type' => "friend_requests#decline_friend_request", as: :decline_friend_request
get '/accept_friend_request/:type' => "friend_requests#accept_friend_request", as: :accept_friend_request
get '/cancel_friend_request/:type' => "friend_requests#cancel_friend_request", as: :cancel_friend_request
get '/unfriend' => "friend_requests#unfriend", as: :unfriend
end
collection do
get :friend_requests
end
end
namespace :student do
resources :students, :path => '/' do
member do
get :friends
get :lesson_plan_progress
post "/join_private_school/:school_id" => "students#join_private_school", as: :join_private_school
get "/private_schools" => "students#private_schools", as: :private_schools
end
collection do
get :departments
post :select_departments
get :list_departments
get :my_lesson_plan
get :special_lesson_plans
end
get '/view_result/:id' => "students#view_result", as: :view_result
get '/lesson_plan/:id' => "students#lesson_plan", as: :lesson_plan
get '/video/:id' => "students#video", as: :video
post '/video_comments/:id' => "students#video_comments", as: :video_comments
get '/like_video/:id' => "students#like_video", as: :like_video
get '/liked_video_users/:id' => "students#liked_video_users", as: :liked_video_users
get '/is_video_completed' => "students#is_video_completed", as: :is_video_completed
get '/assignment_result/:id' => "students#assignment_result", as: :assignment_result
end
resource :users, :except => [:show, :index, :new, :create] do
member do
get :change_password
patch :update_password
end
end
end
namespace :teacher do
resources :teachers, :path => '/' do
resources :subjects do
resources :lesson_plans, :except => [:index] do
member do
get '/change_public' => "lesson_plans#change_public", as: :change_public
get '/change_private' => "lesson_plans#change_private", as: :change_private
post '/copy_lesson_plan' => "lesson_plans#copy_lesson_plan", as: :copy_lesson_plan
get '/play_list_progress' => "lesson_plans#list_play_list_progress", as: :list_play_list_progress
end
resources :lesson_plan_registrations, :only => [:new, :create, :edit, :update]
post '/move_up_down_play_list' => 'lesson_plans#move_up_down_play_list', as: :move_up_down_play_list
resources :comments, only: [:new, :create, :destroy]
resources :videos do
member do
get '/like_video' => "videos#like_video", as: :like_video
get '/liked_video_users' => "videos#liked_video_users", as: :liked_video_users
get '/delete_video_comment' => "videos#delete_video_comment", as: :delete_video_comment
get '/is_video_completed' => "videos#is_video_completed", as: :is_video_completed
post '/copy_video' => "videos#copy_video", as: :copy_video
end
end
resources :documents do
member do
get '/download_file' => "documents#download_file", as: :download_file
get '/like_document' => "documents#like_document", as: :like_document
get '/liked_document_users' => "documents#liked_document_users", as: :liked_document_users
post '/copy_document' => "documents#copy_document", as: :copy_document
end
end
resources :notes do
member do
get '/like_note' => "notes#like_note", as: :like_note
get '/liked_note_users' => "notes#liked_note_users", as: :liked_note_users
end
end
resources :quizzes do
member do
get '/like_quiz' => "quizzes#like_quiz", as: :like_quiz
get '/liked_quiz_users' => "quizzes#liked_quiz_users", as: :liked_quiz_users
match '/change_public' => "quizzes#change_public", as: :change_public, via: [:get, :post]
get '/give_quiz' => "quizzes#give_quiz", as: :give_quiz
get '/preview_quiz' => "quizzes#preview_quiz", as: :preview_quiz
post '/copy_quiz' => "quizzes#copy_quiz", as: :copy_quiz
end
resources :questions do
collection do
get '/fetch_question_options' => 'questions#fetch_question_options'
match '/search_questions' => 'questions#search_questions', as: :search_questions, via: [:get, :post]
post '/select_questions' => 'questions#select_questions', as: :select_questions
end
end
resources :question_groups
resources :sort_questions, only: [:index]
post '/move_up_down' => 'sort_questions#move_up_down', as: :move_up_down
resources :quiz_answers, only: [:new, :create]
resources :quiz_attempts do
member do
get '/download_file' => "quiz_attempts#download_file", as: :download_file
end
end
end
resources :question_banks do
member do
get :fetch_picks
end
resources :sort_questions, only: [:index]
resources :questions do
member do
post :move
end
collection do
get '/fetch_question_options' => 'questions#fetch_question_options'
end
end
end
resources :assignments do
member do
match '/change_public' => "assignments#change_public", as: :change_public, via: [:get, :post]
get '/like_assignment' => "assignments#like_assignment", as: :like_assignment
get '/liked_assignment_users' => "assignments#liked_assignment_users", as: :liked_assignment_users
get '/download_file' => "assignments#download_file", as: :download_file
post '/copy_assignment' => "assignments#copy_assignment", as: :copy_assignment
end
resources :assignment_submissions do
member do
get '/download_file' => "assignment_submissions#download_file", as: :download_file
post '/mark_assignment' => "assignment_submissions#mark_assignment", as: :mark_assignment
end
end
end
end
end
resources :lesson_plans do
resources :videos
resources :documents
resources :notes
resources :quizzes do
member do
match '/change_public' => "quizzes#change_public", as: :change_public, via: [:get, :post]
get '/preview_quiz' => "quizzes#preview_quiz", as: :preview_quiz
end
resources :questions
resources :quiz_attempts do
member do
get '/download_file' => "quiz_attempts#download_file", as: :download_file
end
end
end
resources :question_banks
resources :assignments
end
resources :class_rooms, :only => [:index] do
resources :subjects do
resources :subject_grades, only: [:index] do
collection do
get "/mark_complete" => "subject_grades#mark_complete", as: :mark_complete
end
end
resources :class_room_subjects, only: [:update]
resources :lessons do
resources :attendances, only: [:index]
end
end
end
resources :private_schools do
resources :invitation_promo_codes
resources :private_classes do
member do
get :new_private_lesson_plan
post :create_private_lesson_plan
get "/edit_private_lesson_plan/:private_lesson_plan_id" => "private_classes#edit_private_lesson_plan", as: :edit_private_lesson_plan
post "/update_private_lesson_plan/:private_lesson_plan_id" => "private_classes#update_private_lesson_plan", as: :update_private_lesson_plan
get "/destroy_private_lesson_plan/:private_lesson_plan_id" => "private_classes#destroy_private_lesson_plan", as: :destroy_private_lesson_plan
end
end
end
member do
get :friends
get '/lesson_plans' => "lesson_plans#index", as: :lesson_plans
get '/my_class_rooms' => "class_rooms#index", as: :my_class_rooms
get :new_promo_code
post :create_promo_code
post :leave_private_school
end
collection do
get :departments
post :select_departments
get '/:teacher_id/invitation_promo_codes' => "invitation_promo_codes#index", as: :invitation_promo_codes
end
end
resource :users, :except => [:show, :index, :new, :create] do
member do
get :change_password
patch :update_password
end
end
end
get '/notifications' => 'users#notifications', as: :notifications
delete '/delete_notification/:id' => 'users#delete_notification', as: :delete_notification
get '/notification_status' => 'users#notification_status'
end
You can try this in your routes:
def lesson_plans
resources :lesson_plans, :except => [:index] do
resources :lesson_plan_registrations
resources :comments, only: [:new, :create, :destroy]
end
end
resources :subjects do
lesson_plans
end
lesson_plans
Better way,
concern :lesson_plans do
resources :lesson_plans, :except => [:index] do
resources :lesson_plan_registrations
resources :comments, only: [:new, :create, :destroy]
end
end
resources :subjects do
concerns :lesson_plans
end
concerns :lesson_plans

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 3.1 subdomain based controller routing

I'm currently getting the error:
No route matches [GET] "/tenant_admin"
I was using something like:
http://example.com/accounts/1/tenant_admin
but I'm now passing the account id as a subdomain;
http://AccountName.example.com/
Is it possible to make the url work like this:
http://AccountName.example.com/tenant_admin ?
Routes.rb
get "log_out" => "sessions#destroy", :as => "log_out"
get "log_in" => "sessions#new", :as => "log_in"
get "sign_up" => "users#new", :as => "sign_up"
resources :users
resources :sessions
resources :password_resets
resources :accounts do
resources :tenant_admin
end
constraints(Subdomain) do
match '/' => 'accounts#show'
end
root :to => "welcome#index"
You have to put your tenant routes under resources :accounts and constraints(Subdomain). I don't recommend using copy and paste but a lambda instead.
tenant_routes = lambda do
resources :tenant_admin
end
resources :accounts do
tenant_routes.call
end
constraints(Subdomain) do
tenant_routes.call
end

Rails 3: Stack level too deep when using routes with ":only" or ":as"

I'm currently upgrading my Rails application from 2 to 3. Everything has been going fine until I finished with the routes.rb file. I'll include the contents below:
myApp::Application.routes.draw do
resources :forum_groups
resources :forums do
resources :topics
end
resources :topics do
resources :posts
end
match "confirm_user", :to => "users#confirm"
resources :users do
resources :comments
end
match "moderated_submissions", :to => "submissions#moderated"
resources :submissions do
resources :reviews
end
match "submissions/:id/download" => "submissions#download", :as => :download_submission
match "submissions/:id/trash" => "submissions#trash", :as => :trash_submission
match "submissions/:id/untrash" => "submissions#untrash", :as => :untrash_submission
match "submissions/:id/moderate" => "submissions#moderate", :as => :moderate_submission
match "submissions/:id/unmoderate" => "submissions#unmoderate", :as => :unmoderate_submission
match "submissions/:id/feature" => "submissions#feature", :as => :feature_submission
match "submissions/:id/unfeature" => "submissions#unfeature", :as => :unfeature_submission
#Will work on this later.
#map.user "users/:username", :controller => "users", action => "show"
#map.page "page", :controller => "static_page", :action => "show"
resources :static_pages do
resources :comments
end
resources :categories
resources :comments, :only => [:destroy]
resources :reviews, :only => [:destroy]
resources :features, :as => 'featured'
resources :announcements do
resources :comments
end
root :to => "pages#root"
match "browse", :to => "pages#browse"
match "login", :to => "sessions#new"
match "logout", :to => "sessions#destroy"
match "register", :to => "users#new"
match ":controller/:action/:id(.:format)"
end
The problem occurs when any one of these three lines are present:
resources :comments, :only => [:destroy]
resources :reviews, :only => [:destroy]
resources :features, :as => 'featured'
When any of these lines are present in the routes.rb file I get a, "stack level too deep" error when I try to start the server or the console.
If I remove the statements the application starts fine. If I remove the ":only" and ":as" statements, the application starts fine.
I have tried reordering the routes, and deleting them all except those three and the error still occurs. I have also tried creating a new application from scratch and inserting those three routes. In the case of the new application, it is able to start with those statements.
Any ideas where the problem may lie?

Resources