UPDATE: This was all a horrible mistake - I was updating the wrong routes file!
this does work: get 'users/:id/groups/' => 'users#groups'
I'd like to be able to see groups that belong to a specific user but I'm having trouble setting up a route that would resolve to:
/users/:id/groups
for some reason. I'm guessing devise is getting in the way, perhaps.
i've tried the following:
resources :users
match '/users/:id/groups', to: 'users#groups', via: :get
and
resources :users do
member do
get 'groups'
end
end
such a route never shows up when i call rake routes:
$ rake routes
Prefix Verb URI Pattern Controller#Action
groups GET /groups(.:format) groups#index
POST /groups(.:format) groups#create
new_group GET /groups/new(.:format) groups#new
edit_group GET /groups/:id/edit(.:format) groups#edit
group GET /groups/:id(.:format) groups#show
PATCH /groups/:id(.:format) groups#update
PUT /groups/:id(.:format) groups#update
DELETE /groups/:id(.:format) groups#destroy
calendar GET /calendar(/:year(/:month))(.:format) calendar#index {:year=>/\d{4}/, :month=>/\d{1,2}/}
root GET / calendar#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
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) registrations#cancel
user_registration POST /users(.:format) registrations#create
new_user_registration GET /users/sign_up(.:format) registrations#new
edit_user_registration GET /users/edit(.:format) registrations#edit
PATCH /users(.:format) registrations#update
PUT /users(.:format) registrations#update
DELETE /users(.:format) 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
accept_user_invitation GET /users/invitation/accept(.:format) devise/invitations#edit
remove_user_invitation GET /users/invitation/remove(.:format) devise/invitations#destroy
user_invitation POST /users/invitation(.:format) devise/invitations#create
new_user_invitation GET /users/invitation/new(.:format) devise/invitations#new
PATCH /users/invitation(.:format) devise/invitations#update
PUT /users/invitation(.:format) devise/invitations#update
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
events GET /events(.:format) events#index
POST /events(.:format) events#create
new_event GET /events/new(.:format) events#new
edit_event GET /events/:id/edit(.:format) events#edit
event GET /events/:id(.:format) events#show
PATCH /events/:id(.:format) events#update
PUT /events/:id(.:format) events#update
DELETE /events/:id(.:format) events#destroy
Why are you specifying member when you're trying to nest the resource? Did you try simply
resources :users do
resources :groups, only: :index
end
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 realize this question has been asked many times, but I've tried all the solutions I can find, and have gotten nowhere.
In my view, I have
= link_to "Delete", evint_path(e), :method => :delete, data: {:confirm => 'Are you sure?'}
where e is an instance of evint. I keep getting error messages declaring that I'm missing a GET method for evint:
No route matches [GET] "/evints/5"
This isn't even the case! When I rake routes, I have a GET route for evints.
I have jquery-rails in my Gemfile; I have "require jquery_ujs" in my application.js file. I have five other apps on the same system that work, so I don't think it's a system problem.
The html being generated by my code looks OK:
<a rel="nofollow" href="/evints/5" data-method="delete" data-confirm="Are you sure?">Delete</a>
I've tried removing "//= require tree ." from my application.js file, but that didn't make any difference.
I'm also having trouble signing out of my app, as devise's destroy_session also isn't working!
Does anybody have any ideas? This is driving me crazy!
EDIT: Here are my 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
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
interests GET /interests(.:format) interests#index
POST /interests(.:format) interests#create
new_interest GET /interests/new(.:format) interests#new
edit_interest GET /interests/:id/edit(.:format) interests#edit
interest GET /interests/:id(.:format) interests#show
PATCH /interests/:id(.:format) interests#update
PUT /interests/:id(.:format) interests#update
DELETE /interests/:id(.:format) interests#destroy
events GET /events(.:format) events#index
POST /events(.:format) events#create
new_event GET /events/new(.:format) events#new
edit_event GET /events/:id/edit(.:format) events#edit
event GET /events/:id(.:format) events#show
PATCH /events/:id(.:format) events#update
PUT /events/:id(.:format) events#update
DELETE /events/:id(.:format) events#destroy
images GET /images(.:format) images#index
POST /images(.:format) images#create
new_image GET /images/new(.:format) images#new
image GET /images/:id(.:format) images#show
DELETE /images/:id(.:format) images#destroy
evints GET /evints(.:format) evints#index
POST /evints(.:format) evints#create
new_evint GET /evints/new(.:format) evints#new
evint DELETE /evints/:id(.:format) evints#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 PATCH /projects/:id(.:format) projects#update
PUT /projects/:id(.:format) projects#update
projectimages GET /projectimages(.:format) projectimages#index
POST /projectimages(.:format) projectimages#create
new_projectimage GET /projectimages/new(.:format) projectimages#new
projectimage GET /projectimages/:id(.:format) projectimages#show
DELETE /projectimages/:id(.:format) projectimages#destroy
welcome_index GET /welcome/index(.:format) welcome#index
root GET / welcome#index
welcome_readpdf GET /welcome/readpdf(.:format) welcome#readpdf
Im having a problem routing my custom Users controller and devise gem.
When i try to reach http://localhost:3000/users
<%= link_to 'Users', users_path, class: 'navbar-brand' %>
I get error:
Could not find devise mapping for path "/users". 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]
If i run command rake routes i get this output:
Prefix Verb URI Pattern Controller#Action
root GET / static_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) 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
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
account_update PATCH /account_update(.:format) users#update
And this are my routes
root 'static_pages#home'
devise_for :users
resources :users
as :user do
patch 'account_update' => 'users#update'
get 'users' => 'users#index'
end
How to tell rails that on /users it should go to controller Users and select index page
You can try something like that,
devise_for :users
devise_scope :user do
end
I am using devise and trying to use token code with devise registration page, I know I have some issue with the routes to set the link. The link looks like this
http://localhost:3000/users/sign_up.asdfsdfasdffffffffffffffasdfasdf
a dot in between the query string and it doesn't work.
my routes.rb is this
devise_for :users ,:controllers => { :registrations => "registrations" } do
#get "/register", :to => "devise/registrations#new"
get 'users/sign_up/:invitation_token' => "registrations#new", :as => :reg_with_code
end
please help me to set a proper link with the slash in between .
here is may rake routes
invitations GET /invitations(.:format) invitations#index
POST /invitations(.:format) invitations#create
new_invitation GET /invitations/new(.:format) invitations#new
edit_invitation GET /invitations/:id/edit(.:format) invitations#edit
invitation GET /invitations/:id(.:format) invitations#show
PUT /invitations/:id(.:format) invitations#update
DELETE /invitations/:id(.:format)
invitations#destroy
reg_with_code GET /users/sign_up/:invitation_token(.:format) registrations#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) registrations#cancel
user_registration POST /users(.:format) registrations#create
new_user_registration GET /users/sign_up(.:format) registrations#new
edit_user_registration GET /users/edit(.:format) registrations#edit
PUT /users(.:format) registrations#update
DELETE /users(.:format) registrations#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
PUT /users/:id(.:format) users#update
DELETE /users/:id(.:format) users#destroy
root / home#index
In the email template, change the token link to
<%= link_to "Sign Up", reg_with_code_path(#token) %>
since you have put a :as => :reg_with_code in you routes.rb file.
You can try with this:
reg_with_code_path(invitation_token: #token)
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.