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
Related
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
Set up Authentication with AngularJS and Ruby on Rails. Try to do under this article https://www.airpair.com/ruby-on-rails/posts/authentication-with-angularjs-and-ruby-on-rails. But when run the test with rspec have the same error
Authentication login with valid inputs
Failure/Error: Unable to find matching line from backtrace
ActionController::RoutingError:
No route matches [GET] "/sign_in"
In rake routes have:
Prefix Verb URI Pattern Controller#Action
new_user_session GET /users/sign_in(.:format) devise/sessions#new
user_session POST /users/sign_in(.:format) devise/sessions#create
destroy_user_session GET /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) 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
PATCH /users(.:format) devise/registrations#update
PUT /users(.:format) devise/registrations#update
DELETE /users(.:format) devise/registrations#destroy
user_confirmation POST /users/confirmation(.:format) devise/confirmations#create
new_user_confirmation GET /users/confirmation/new(.:format) devise/confirmations#new
GET /users/confirmation(.:format) devise/confirmations#show
root GET / devise/sessions#new
user_root GET /persons/profile(.:format) persons#profile
next_page GET /index(.:format) persons#index
GET /omniauth/:provider/callback(.:format) devise_token_auth/omniauth_callbacks#redirect_callbacks
As your routes say...you need to use /users/sign_in with GET request.
You are using /sign_in which doesn't exist...
you can directly use new_user_session_path
if you actually want to use /sign_in,edit your routes and add this
get 'sign_in' => 'devise/sessions#new'
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 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
Here is the output of 'rake routes'
$ 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
admin_root /admin(.:format) admin/dashboard#index
admin_dashboard /admin/dashboard(.:format) admin/dashboard#index
admin_user PUT /admin/users/:id(.:format) admin/users#update
batch_action_admin_users POST /admin/users/batch_action(.:format) admin/users#batch_action
admin_users GET /admin/users(.:format) admin/users#index
POST /admin/users(.:format) admin/users#create
new_admin_user GET /admin/users/new(.:format) admin/users#new
edit_admin_user GET /admin/users/:id/edit(.:format) admin/users#edit
GET /admin/users/:id(.:format) admin/users#show
PUT /admin/users/:id(.:format) admin/users#update
DELETE /admin/users/:id(.:format) admin/users#destroy
root / home#index
And here is an excerpt from the logs
Started POST "/admin/users/batch_action" for 127.0.0.1 at 2013-01-18 23:07:07 +0530
Processing by Admin::UsersController#create as HTML
Why is /admin/users/batch_action getting routed to Admin::UsersController#create, when the routes shows
batch_action_admin_users POST /admin/users/batch_action(.:format) admin/users#batch_action
I am using ActiveAdmin and these are the routes that it generates.
It seems like you are using resources for routing admin/users controller, so POST http verb is defaulted to create action in the controller.
If you would like to add another restful POST controller action, do something like this,
scope "admin" do
resources :users do
member do
post 'batch_action'
end
end
end
I don't know how your routes.rb looks like, so it might look different in your routes.rb file. But it should look similar.