I have problem with pointing as root controller which has only one action called index. My current routes.rb looks like this:
get 'dashboard', to: 'dashboard#index'
resources :categories
resources :projects do
resources :issues
resources :attachments
end
devise_for :users
devise_scope :user do
authenticated :user do
root :to => 'dashboard#index'
end
unauthenticated :user do
root :to => 'devise/sessions#new'
end
end
Any my controller:
class DashboardController < ApplicationController
authorize_resource
def index
#test = 'test'
end
end
But each time I enter localhost:3000 I get "NameError at /
uninitialized constant Dashboard". What am I doing wrong?
Thanks in advance!
edit:
rake routes shows this:
dashboard GET /dashboard(.:format) dashboard#index
categories GET /categories(.:format) categories#index
POST /categories(.:format) categories#create
new_category GET /categories/new(.:format) categories#new
edit_category GET /categories/:id/edit(.:format) categories#edit
category GET /categories/:id(.:format) categories#show
PUT /categories/:id(.:format) categories#update
DELETE /categories/:id(.:format) categories#destroy
project_issues GET /projects/:project_id/issues(.:format) issues#index
POST /projects/:project_id/issues(.:format) issues#create
new_project_issue GET /projects/:project_id/issues/new(.:format) issues#new
edit_project_issue GET /projects/:project_id/issues/:id/edit(.:format) issues#edit
project_issue GET /projects/:project_id/issues/:id(.:format) issues#show
PUT /projects/:project_id/issues/:id(.:format) issues#update
DELETE /projects/:project_id/issues/:id(.:format) issues#destroy
project_attachments GET /projects/:project_id/attachments(.:format) attachments#index
POST /projects/:project_id/attachments(.:format) attachments#create
new_project_attachment GET /projects/:project_id/attachments/new(.:format) attachments#new
edit_project_attachment GET /projects/:project_id/attachments/:id/edit(.:format) attachments#edit
project_attachment GET /projects/:project_id/attachments/:id(.:format) attachments#show
PUT /projects/:project_id/attachments/:id(.:format) attachments#update
DELETE /projects/:project_id/attachments/:id(.:format) attachments#destroy
projects GET /projects(.:format) projects#index
POST /projects(.:format) projects#create
new_project GET /projects/new(.:format) projects#new
edit_project GET /projects/:id/edit(.:format) projects#edit
project GET /projects/:id(.:format) projects#show
PUT /projects/:id(.:format) projects#update
DELETE /projects/:id(.:format) projects#destroy
new_user_session GET /users/sign_in(.:format) devise/sessions#new
user_session POST /users/sign_in(.:format) devise/sessions#create
destroy_user_session DELETE /users/sign_out(.:format) devise/sessions#destroy
user_password POST /users/password(.:format) devise/passwords#create
new_user_password GET /users/password/new(.:format) devise/passwords#new
edit_user_password GET /users/password/edit(.:format) devise/passwords#edit
PUT /users/password(.:format) devise/passwords#update
cancel_user_registration GET /users/cancel(.:format) devise/registrations#cancel
user_registration POST /users(.:format) devise/registrations#create
new_user_registration GET /users/sign_up(.:format) devise/registrations#new
edit_user_registration GET /users/edit(.:format) devise/registrations#edit
PUT /users(.:format) devise/registrations#update
DELETE /users(.:format) devise/registrations#destroy
root / dashboard#index
root / devise/sessions#new
Related
I have created a new "public_speaking" route by adding an entry in pages_controller.rb:
def public_speaking
end
I also created a barebones view file for "public_speaking.html.erb" and added a route in routes.rb as follows:
get 'home/public_speaking'
-or-
get 'public_speaking', to: 'pages#public_speaking'
I have tried both versions of the route and it worked in one of my branches, but I tried copying and pasting the code into another branch and the same steps don't yield any entry for a "public_speaking" route when I run "rails routes" in my console.
What on earth could cause a new route to be created in one branch but not another? What else should I try?
The full routes.rb file looks like this:
Rails.application.routes.draw do
root to: "pages#home"
get 'home/public_speaking'
get 'public_speaking', to: 'pages#public_speaking'
devise_for :users, controllers: { registrations: 'users/registrations' }
resources :users do
resource :profile
end
get 'about', to: 'pages#about'
resources :contacts, only: [:create]
get 'contact-us', to: 'contacts#new', as: 'new_contact'
get 'home/public_speaking'
get 'public_speaking', to: 'pages#public_speaking'
end
The full pages controller looks like:
class PagesController < ApplicationController
# GET request for / which is our home page
def home
#basic_plan = Plan.find(1)
#pro_plan = Plan.find(2)
end
def about
end
def offerings
end
def public_speaking
end
end
Editing to add the results of "rails routes" for the working branch:
rails routes
Prefix Verb URI Pattern Controller#Action
pages_home GET /pages/home(.:format) pages#home
pages_about GET /pages/about(.:format) pages#about
pages_offerings GET /pages/offerings(.:format) pages#offerings
pages_public_speaking GET /pages/public_speaking(.:format) pages#public_speaking
root GET / pages#home
new_user_session GET /users/sign_in(.:format) devise/sessions#new
user_session POST /users/sign_in(.:format) devise/sessions#create
destroy_user_session DELETE /users/sign_out(.:format) devise/sessions#destroy
user_password POST /users/password(.:format) devise/passwords#create
new_user_password GET /users/password/new(.:format) devise/passwords#new
edit_user_password GET /users/password/edit(.:format) devise/passwords#edit
PATCH /users/password(.:format) devise/passwords#update
PUT /users/password(.:format) devise/passwords#update
cancel_user_registration GET /users/cancel(.:format) users/registrations#cancel
user_registration POST /users(.:format) users/registrations#create
new_user_registration GET /users/sign_up(.:format) users/registrations#new
edit_user_registration GET /users/edit(.:format) users/registrations#edit
PATCH /users(.:format) users/registrations#update
PUT /users(.:format) users/registrations#update
DELETE /users(.:format) users/registrations#destroy
user_profile POST /users/:user_id/profile(.:format) profiles#create
new_user_profile GET /users/:user_id/profile/new(.:format) profiles#new
edit_user_profile GET /users/:user_id/profile/edit(.:format) profiles#edit
GET /users/:user_id/profile(.:format) profiles#show
PATCH /users/:user_id/profile(.:format) profiles#update
PUT /users/:user_id/profile(.:format) profiles#update
DELETE /users/:user_id/profile(.:format) profiles#destroy
users GET /users(.:format) users#index
POST /users(.:format) users#create
new_user GET /users/new(.:format) users#new
edit_user GET /users/:id/edit(.:format) users#edit
user GET /users/:id(.:format) users#show
PATCH /users/:id(.:format) users#update
PUT /users/:id(.:format) users#update
DELETE /users/:id(.:format) users#destroy
about GET /about(.:format) pages#about
contacts POST /contacts(.:format) contacts#create
new_contact GET /contact-us(.:format) contacts#new
offerings GET /offerings(.:format) pages#offerings
ubuntu#ip-172-31-91-225:~/environment/saasapp$
And the branch where it doesn't work:
rails routes
Prefix Verb URI Pattern Controller#Action
root GET / pages#home
new_user_session GET /users/sign_in(.:format) devise/sessions#new
user_session POST /users/sign_in(.:format) devise/sessions#create
destroy_user_session DELETE /users/sign_out(.:format) devise/sessions#destroy
user_password POST /users/password(.:format) devise/passwords#create
new_user_password GET /users/password/new(.:format) devise/passwords#new
edit_user_password GET /users/password/edit(.:format) devise/passwords#edit
PATCH /users/password(.:format) devise/passwords#update
PUT /users/password(.:format) devise/passwords#update
cancel_user_registration GET /users/cancel(.:format) users/registrations#cancel
user_registration POST /users(.:format) users/registrations#create
new_user_registration GET /users/sign_up(.:format) users/registrations#new
edit_user_registration GET /users/edit(.:format) users/registrations#edit
PATCH /users(.:format) users/registrations#update
PUT /users(.:format) users/registrations#update
DELETE /users(.:format) users/registrations#destroy
user_profile POST /users/:user_id/profile(.:format) profiles#create
new_user_profile GET /users/:user_id/profile/new(.:format) profiles#new
edit_user_profile GET /users/:user_id/profile/edit(.:format) profiles#edit
GET /users/:user_id/profile(.:format) profiles#show
PATCH /users/:user_id/profile(.:format) profiles#update
PUT /users/:user_id/profile(.:format) profiles#update
DELETE /users/:user_id/profile(.:format) profiles#destroy
users GET /users(.:format) users#index
POST /users(.:format) users#create
new_user GET /users/new(.:format) users#new
edit_user GET /users/:id/edit(.:format) users#edit
user GET /users/:id(.:format) users#show
PATCH /users/:id(.:format) users#update
PUT /users/:id(.:format) users#update
DELETE /users/:id(.:format) users#destroy
about GET /about(.:format) pages#about
contacts POST /contacts(.:format) contacts#create
new_contact GET /contact-us(.:format) contacts#new
offerings GET /offerings(.:format) pages#offerings
I have one controller called Page_controller and another one called Categories_controller. Now whenever the home method in the Page_controller is called I wanna be redirected to the a´categories controller, as I wanna control the Category view from that moment on. This is what I have written:
class PagesController < ApplicationController
def home
#categories = Category.all
redirect_to category_url(#category)
end
end
but I get an error when I open the server saying:
undefined method `category_url' for #<PagesController:0x000000000b24ce20>
for the line:
redirect_to category_url(#category)
Does anyone know how I could pass control from one controller to the other? I am really desperate so apreciate any help you can provide
EDIT: this is my routes.rb file:
Rails.application.routes.draw do
resources :comments
#resources :categories
root to: 'pages#home'
get 'index', to: 'controller_category#index'
devise_for :users
end
And the routes printed out from the console:
C:\Users\andri\Desktop\proj>bundle exec rake routes
Prefix Verb URI Pattern Controller#Action
comments GET /comments(.:format) comments#index
POST /comments(.:format) comments#create
new_comment GET /comments/new(.:format) comments#new
edit_comment GET /comments/:id/edit(.:format) comments#edit
comment GET /comments/:id(.:format) comments#show
PATCH /comments/:id(.:format) comments#update
PUT /comments/:id(.:format) comments#update
DELETE /comments/:id(.:format) comments#destroy
root GET / pages#home
index GET /index(.:format) controller_category#index
new_user_session GET /users/sign_in(.:format) devise/sessions#new
user_session POST /users/sign_in(.:format) devise/sessions#create
destroy_user_session DELETE /users/sign_out(.:format) devise/sessions#destroy
new_user_password GET /users/password/new(.:format) devise/passwords#new
edit_user_password GET /users/password/edit(.:format) devise/passwords#edit
user_password PATCH /users/password(.:format) devise/passwords#update
PUT /users/password(.:format) devise/passwords#update
POST /users/password(.:format) devise/passwords#create
cancel_user_registration GET /users/cancel(.:format) devise/registrations#cancel
new_user_registration GET /users/sign_up(.:format) devise/registrations#new
edit_user_registration GET /users/edit(.:format) devise/registrations#edit
user_registration PATCH /users(.:format) devise/registrations#update
PUT /users(.:format) devise/registrations#update
DELETE /users(.:format) devise/registrations#destroy
POST /users(.:format) devise/registrations#create
rails_service_blob GET /rails/active_storage/blobs/:signed_id/*filename(.:format) active_storage/blobs#show
rails_blob_representation GET /rails/active_storage/representations/:signed_blob_id/:variation_key/*filename(.:format) active_storage/representations#show
rails_disk_service GET /rails/active_storage/disk/:encoded_key/*filename(.:format) active_storage/disk#show
update_rails_disk_service PUT /rails/active_storage/disk/:encoded_token(.:format) active_storage/disk#update
rails_direct_uploads POST /rails/active_storage/direct_uploads(.:format) active_storage/direct_uploads#create
Uncomment this line in your routes.rb file:
#resources :categories
That will define a set of routes for categories, which will provide you with methods such as category_url(category).
You'll also need a CategoriesController, otherwise your next problem will be that the redirect produces an error (no such controller). And you'll need to implement CategoriesController#show.
See https://guides.rubyonrails.org/getting_started.html
and https://guides.rubyonrails.org/routing.html
Routing Error
No route matches {:action=>"edit", :controller=>"statuses", :id=>nil}
When http://0.0.0.0:3000/users/2
Dont understand why it says :controller=>"statuses" when my route file says:
Treebook::Application.routes.draw do
get "users/show"
resources :credits
resources :merchants
devise_for :users
resources :statuses
root to: 'statuses#index'
get 'users/:id', to: 'users#show'
Rake Route
root / statuses#index
credits GET /credits(.:format) credits#index
POST /credits(.:format) credits#create
new_credit GET /credits/new(.:format) credits#new
edit_credit GET /credits/:id/edit(.:format) credits#edit
credit GET /credits/:id(.:format) credits#show
PUT /credits/:id(.:format) credits#update
DELETE /credits/:id(.:format) credits#destroy
merchants GET /merchants(.:format) merchants#index
POST /merchants(.:format) merchants#create
new_merchant GET /merchants/new(.:format) merchants#new
edit_merchant GET /merchants/:id/edit(.:format) merchants#edit
merchant GET /merchants/:id(.:format) merchants#show
PUT /merchants/:id(.:format) merchants#update
DELETE /merchants/:id(.:format) merchants#destroy
statuses GET /statuses(.:format) statuses#index
POST /statuses(.:format) statuses#create
new_status GET /statuses/new(.:format) statuses#new
edit_status GET /statuses/:id/edit(.:format) statuses#edit
status GET /statuses/:id(.:format) statuses#show
PUT /statuses/:id(.:format) statuses#update
DELETE /statuses/:id(.:format) statuses#destroy
new_user_session GET /users/sign_in(.:format) devise/sessions#new
user_session POST /users/sign_in(.:format) devise/sessions#create
destroy_user_session DELETE /users/sign_out(.:format) devise/sessions#destroy
user_password POST /users/password(.:format) devise/passwords#create
new_user_password GET /users/password/new(.:format) devise/passwords#new
edit_user_password GET /users/password/edit(.:format) devise/passwords#edit
PUT /users/password(.:format) devise/passwords#update
cancel_user_registration GET /users/cancel(.:format) devise/registrations#cancel
user_registration POST /users(.:format) devise/registrations#create
new_user_registration GET /users/sign_up(.:format) devise/registrations#new
edit_user_registration GET /users/edit(.:format) devise/registrations#edit
PUT /users(.:format) devise/registrations#update
DELETE /users(.:format) devise/registrations#destroy
user GET /users/:id(.:format) users#show
get "users/show" - that will probably be causing your problem
Here's a better routes file for you:
root to: "statuses#index"
resources :credits, :merchants, :statuses
devise_for :users
resources :users, only: [:show]
Aggggg
The problem was on some footer links that I copy pasted. I just deleted both links since I dont need them. Incredible how can your attention gets stuck in a point far away from the root problem.
|
I have added the omniauth and devise gems and was adding facebook login support. This is my routes.rb file:
resources :authentications do
match 'auth/:provider/callback' => 'authentications/#create', :via => :post
end
I tried post as well as get in the via part.
Here is the controller for authentications controller.
def create
auth = request.env["rack.auth"]
current_user.authentications.find_or_create_by_provider_and_uid(auth['provider'], auth['uid'])
flash[:notice] = "Authentication successful."
redirect_to authentications_url
end
Here is the rake routes output
rake routes
authentications GET /authentications(.:format) authentications#index
POST /authentications(.:format) authentications#create
new_authentication GET /authentications/new(.:format) authentications#new
edit_authentication GET /authentications/:id/edit(.:format) authentications#edit
authentication GET /authentications/:id(.:format) authentications#show
PUT /authentications/:id(.:format) authentications#update
DELETE /authentications/:id(.:format) authentications#destroy
conferences GET /conferences(.:format) conferences#index
POST /conferences(.:format) conferences#create
new_conference GET /conferences/new(.:format) conferences#new
edit_conference GET /conferences/:id/edit(.:format) conferences#edit
conference GET /conferences/:id(.:format) conferences#show
PUT /conferences/:id(.:format) conferences#update
DELETE /conferences/:id(.:format) conferences#destroy
profiles GET /profiles(.:format) profiles#index
POST /profiles(.:format) profiles#create
new_profile GET /profiles/new(.:format) profiles#new
edit_profile GET /profiles/:id/edit(.:format) profiles#edit
profile GET /profiles/:id(.:format) profiles#show
PUT /profiles/:id(.:format) profiles#update
DELETE /profiles/:id(.:format) profiles#destroy
GET /conferences(.:format) conferences#index
POST /conferences(.:format) conferences#create
GET /conferences/new(.:format) conferences#new
GET /conferences/:id/edit(.:format) conferences#edit
GET /conferences/:id(.:format) conferences#show
PUT /conferences/:id(.:format) conferences#update
DELETE /conferences/:id(.:format) conferences#destroy
activity_bigbluebutton_server GET /bigbluebutton/servers/:id/activity(.:format) bigbluebutton/servers#activity
rooms_bigbluebutton_server GET /bigbluebutton/servers/:id/rooms(.:format) bigbluebutton/servers#rooms
bigbluebutton_servers GET /bigbluebutton/servers(.:format) bigbluebutton/servers#index
POST /bigbluebutton/servers(.:format) bigbluebutton/servers#create
new_bigbluebutton_server GET /bigbluebutton/servers/new(.:format) bigbluebutton/servers#new
edit_bigbluebutton_server GET /bigbluebutton/servers/:id/edit(.:format) bigbluebutton/servers#edit
bigbluebutton_server GET /bigbluebutton/servers/:id(.:format) bigbluebutton/servers#show
PUT /bigbluebutton/servers/:id(.:format) bigbluebutton/servers#update
DELETE /bigbluebutton/servers/:id(.:format) bigbluebutton/servers#destroy
external_bigbluebutton_rooms GET /bigbluebutton/rooms/external(.:format) bigbluebutton/rooms#external
POST /bigbluebutton/rooms/external(.:format) bigbluebutton/rooms#external_auth
join_bigbluebutton_room GET /bigbluebutton/rooms/:id/join(.:format) bigbluebutton/rooms#join
running_bigbluebutton_room GET /bigbluebutton/rooms/:id/running(.:format) bigbluebutton/rooms#running
end_bigbluebutton_room GET /bigbluebutton/rooms/:id/end(.:format) bigbluebutton/rooms#end
invite_bigbluebutton_room GET /bigbluebutton/rooms/:id/invite(.:format) bigbluebutton/rooms#invite
join_mobile_bigbluebutton_room GET /bigbluebutton/rooms/:id/join_mobile(.:format) bigbluebutton/rooms#join_mobile
POST /bigbluebutton/rooms/:id/join(.:format) bigbluebutton/rooms#auth
bigbluebutton_rooms GET /bigbluebutton/rooms(.:format) bigbluebutton/rooms#index
POST /bigbluebutton/rooms(.:format) bigbluebutton/rooms#create
new_bigbluebutton_room GET /bigbluebutton/rooms/new(.:format) bigbluebutton/rooms#new
edit_bigbluebutton_room GET /bigbluebutton/rooms/:id/edit(.:format) bigbluebutton/rooms#edit
bigbluebutton_room GET /bigbluebutton/rooms/:id(.:format) bigbluebutton/rooms#show
PUT /bigbluebutton/rooms/:id(.:format) bigbluebutton/rooms#update
DELETE /bigbluebutton/rooms/:id(.:format) bigbluebutton/rooms#destroy
/auth/:provider/callback(.:format) authentications/#create
root / profiles#new
new_user_session GET /users/sign_in(.:format) devise/sessions#new
user_session POST /users/sign_in(.:format) devise/sessions#create
destroy_user_session DELETE /users/sign_out(.:format) devise/sessions#destroy
user_password POST /users/password(.:format) devise/passwords#create
new_user_password GET /users/password/new(.:format) devise/passwords#new
edit_user_password GET /users/password/edit(.:format) devise/passwords#edit
PUT /users/password(.:format) devise/passwords#update
cancel_user_registration GET /users/cancel(.:format) devise/registrations#cancel
user_registration POST /users(.:format) devise/registrations#create
new_user_registration GET /users/sign_up(.:format) devise/registrations#new
edit_user_registration GET /users/edit(.:format) devise/registrations#edit
PUT /users(.:format) devise/registrations#update
DELETE /users(.:format) devise/registrations#destroy
This
match 'auth/:provider/callback' => 'authentications/#create', :via => :post
Should be
match 'auth/:provider/callback' => 'authentications#create', :via => :post
Where authentications is controller & create is method
I'm getting a strange error with my routing. I've installed the blogit gem but I don't think this is causing this problem.
undefined local variable or method `locations_path'
Here is my routes file:
AppName::Application.routes.draw do
devise_for :users
root :to => 'locations#index'
mount Blogit::Engine => "/blog", :as => "blog"
resources :locations do
collection do
get 'location'
end
end
and here's my rake routes:
new_user_session GET /users/sign_in(.:format) devise/sessions#new
user_session POST /users/sign_in(.:format) devise/sessions#create
destroy_user_session DELETE /users/sign_out(.:format) devise/sessions#destroy
user_password POST /users/password(.:format) devise/passwords#create
new_user_password GET /users/password/new(.:format) devise/passwords#new
edit_user_password GET /users/password/edit(.:format) devise/passwords#edit
PUT /users/password(.:format) devise/passwords#update
cancel_user_registration GET /users/cancel(.:format) devise/registrations#cancel
user_registration POST /users(.:format) devise/registrations#create
new_user_registration GET /users/sign_up(.:format) devise/registrations#new
edit_user_registration GET /users/edit(.:format) devise/registrations#edit
PUT /users(.:format) devise/registrations#update
DELETE /users(.:format) devise/registrations#destroy
root / locations#index
blog /blog Blogit::Engine
location_locations GET /locations/location(.:format) locations#location
locations GET /locations(.:format) locations#index
POST /locations(.:format) locations#create
new_location GET /locations/new(.:format) locations#new
edit_location GET /locations/:id/edit(.:format) locations#edit
location GET /locations/:id(.:format) locations#show
PUT /locations/:id(.:format) locations#update
DELETE /locations/:id(.:format) locations#destroy
Routes for Blogit::Engine:
/posts/page/:page(.:format) blogit/posts#index
tagged_blog_posts /posts/tagged/:tag(.:format) blogit/posts#tagged
post_comments POST /posts/:post_id/comments(.:format) blogit/comments#create
post_comment DELETE /posts/:post_id/comments/:id(.:format) blogit/comments#destroy
posts GET /posts(.:format) blogit/posts#index
POST /posts(.:format) blogit/posts#create
new_post GET /posts/new(.:format) blogit/posts#new
edit_post GET /posts/:id/edit(.:format) blogit/posts#edit
post GET /posts/:id(.:format) blogit/posts#show
PUT /posts/:id(.:format) blogit/posts#update
DELETE /posts/:id(.:format) blogit/posts#destroy
root / blogit/posts#index
Any suggestions as to why this may be happening would be great.
Thanks,
James
This was an issue with my blogit configuration.
People can find the full thread here:
https://github.com/KatanaCode/blogit/issues/8
Thanks for all your help!
James