I type in a new email, password, and password confirmation in my Devise app. When I go to actually do the signup, I get the following error:
RoutingError
No route matches [POST] "/users/sign_up"
Try running rake routes for more information on available routes.
It looks like new_registration_path takes you to users/sign_up, which it doesn't know about (at least when getting a POST). How do I make it recognize this?
Below are some relevant bits of code.
Here's the (possibly) relevant routes.rb:
devise_for :users
resources :users
Here's the output of 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
static_pages_home GET /static_pages/home(.:format) static_pages#home
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
businesses GET /businesses(.:format) businesses#index
POST /businesses(.:format) businesses#create
new_business GET /businesses/new(.:format) businesses#new
ed it_business GET /businesses/:id/edit(.:format) businesses#edit
business GET /businesses/:id(.:format) businesses#show
PUT /businesses/:id(.:format) businesses#update
DELETE /businesses/:id(.:format) businesses#destroy
root / static_pages#home
Here's the form in registrations/new.html.erb:
<%= form_for(resource, :as => resource_name, :url => new_registration_path(resource_name)) do |f| %>
...
<% end %>
I think you should use registration_path instead of new_registration_path because sign up is performed via POST request to /users.
<%= form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| %>
...
<% end %>
Related
Hi and thanks in advance for any help.
I have an admin page: views/admin/admin_page
and a form located in: views/videos/_new
The form renders nicely inside of the admin_page however when I submit the form the url seems to inherit "admin" from either my AdminController or my views/admin folder and appends it to the url I specify in my form. For instance the form below posts to /admin/users/profile/videos.
Can someone help me fix this, please?
videos/_new.html.erb
<%= form_for #video, url: 'users/profile/videos', controller: "videos", method: 'post', :html => { multipart: true } do |f| %>
<div class="form-group">
<%= f.label :avatar %>
<%= f.file_field :avatar, class: 'form-control' %>
</div>
<%= f.submit 'Submit',class: 'btn btn-default' %>
Routes:
Rails.application.routes.draw do
devise_for :users
resources :users do
resource :profile do
resources :videos
end
end
get 'admin/ad_pg', :to => 'admin#ad_pg'
end
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
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
user_profile_videos GET /users/:user_id/profile/videos(.:format) videos#index
POST /users/:user_id/profile/videos(.:format) videos#create
new_user_profile_video GET /users/:user_id/profile/videos/new(.:format) videos#new
edit_user_profile_video GET /users/:user_id/profile/videos/:id/edit(.:format) videos#edit
user_profile_video GET /users/:user_id/profile/videos/:id(.:format) videos#show
PATCH /users/:user_id/profile/videos/:id(.:format) videos#update
PUT /users/:user_id/profile/videos/:id(.:format) videos#update
DELETE /users/:user_id/profile/videos/:id(.:format) videos#destroy
new_user_profile GET /users/:user_id/profile/new(.:format) profiles#new
edit_user_profile GET /users/:user_id/profile/edit(.:format) profiles#edit
user_profile 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
POST /users/:user_id/profile(.:format) profiles#create
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
root GET / pages#home
contacts GET /contacts(.:format) contacts#index
POST /contacts(.:format) contacts#create
new_contact GET /contacts/new(.:format) contacts#new
edit_contact GET /contacts/:id/edit(.:format) contacts#edit
contact GET /contacts/:id(.:format) contacts#show
PATCH /contacts/:id(.:format) contacts#update
PUT /contacts/:id(.:format) contacts#update
DELETE /contacts/:id(.:format) contacts#destroy
admin_ad_pg GET /admin/ad_pg(.:format) admin#ad_pg
admin/ad_pg is my "admin page"
Thanks again,
Matt
The matching route is /users/:user_id/profile/videos(.:format) but your url is users/profile/videos which has two problems. It is not absolute (it should start with a '/' and it does not include the :user_id segment). You should probably use the helper:
<%= form_for #video, url: user_profile_videos(user_id: #video.user_id), ...
Or something similar
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'm trying to add a simple custom action cancelaccount to a user model generated by devise, but having a hard time getting the routing right.
Here is what's in route.rb
devise_for :users, controllers: { registrations: "userregistrations", sessions: "sessions" } do
get '/users/:id/cancelaccount', to: 'userregistrations#cancelaccount', as: 'cancelaccount'
end
Here is the controller
class UserregistrationsController < Devise::RegistrationsController
def create
...
end
def cancelaccount
authenticate_user!
Rails.logger.debug {"&& cancel"}
#user = User.find(params[:id])
unless (#user == current_user)
redirect_to :back, :alert => "Access denied."
end
end
end
Here is the link_to line in the HTML:
<li><%= link_to "Cancel Account", {controller: "userregistrations", action: "cancelaccount", id: current_user.id} %></li>
This is the error I get:
No route matches {:action=>"cancelaccount", :controller=>"userregistrations", :id=>12}
If I change the link_to link to:
<li><%= link_to "Cancel Account", cancelaccount_path(#user) %></li>
The error is:
undefined method `cancelaccount_path' for #<#:0x00000006a5d4c0>
Any help is highly appreciated.
Here is the result of "rake routes":
new_user_session GET /users/sign_in(.:format) sessions#new
user_session POST /users/sign_in(.:format) sessions#create
destroy_user_session DELETE /users/sign_out(.:format) sessions#destroy
user_omniauth_authorize GET|POST /users/auth/:provider(.:format) devise/omniauth_callbacks#passthru {:provider=>/(?!)/}
user_omniauth_callback GET|POST /users/auth/:action/callback(.:format) devise/omniauth_callbacks#:action
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) userregistrations#cancel
user_registration POST /users(.:format) userregistrations#create
new_user_registration GET /users/sign_up(.:format) userregistrations#new
edit_user_registration GET /users/edit(.:format) userregistrations#edit
PATCH /users(.:format) userregistrations#update
PUT /users(.:format) userregistrations#update
DELETE /users(.:format) userregistrations#destroy
root GET / static_pages#home
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
userpreferences GET /userpreferences(.:format) userpreferences#index
POST /userpreferences(.:format) userpreferences#create
new_userpreference GET /userpreferences/new(.:format) userpreferences#new
edit_userpreference GET /userpreferences/:id/edit(.:format) userpreferences#edit
userpreference GET /userpreferences/:id(.:format) userpreferences#show
PATCH /userpreferences/:id(.:format) userpreferences#update
PUT /userpreferences/:id(.:format) userpreferences#update
DELETE /userpreferences/:id(.:format) userpreferences#destroy
signup GET /signup(.:format) devise/registrations#new
edit_profile GET /edit_profile(.:format) devise/registrations#edit
change_password GET /change_password(.:format) devise/passwords#edit
sign_in GET /sign_in(.:format) devise/sessions#new
sign_out GET /sign_out(.:format) devise/sessions#destroy
confirmation GET /confirmation(.:format) devise/confirmations#new
unlock_account GET /unlock_account(.:format) devise/unlocks#new
GET /signup(.:format) trainer/registrations#new
edit GET /edit(.:format) trainer/registrations#edit
GET /sign_in(.:format) devise/sessions#new
GET /sign_out(.:format) devise/sessions#destroy
GET /confirmation(.:format) devise/confirmations#new
GET /unlock_account(.:format) devise/unlocks#new
I am not sure what is wrong with your devise_for block, but you can easily add this route outside of it:
devise_for :users, controllers: { registrations: "userregistrations", sessions: "sessions" }
match '/users/:id/cancelaccount' => 'registrations#cancelaccount', via: 'get', as: 'cancelaccount'
Which will add the route you want:
cancelaccount GET /users/:id/cancelaccount(.:format) registrations#cancelaccount
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)
I have these urls:
http://localhost:3000/assets
http://localhost:3000/assets/new
http://localhost:3000/assets/34
http://localhost:3000/assets/34/edit
they work in my app.
I have this routes.rb file:
devise_for :users
match "listings/show_notes" => "listings#show_notes", :as => :show_notes
resources :users
resources :listings
resources :assets
authenticated :user do
root :to => "listings#index"
end
#this route is for file downloads
match "assets/get/:id" => "assets#get", :as => :download
resources :admin_dash_board, :only => :index
I have the following output when I type in 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
show_notes /listings/show_notes(.:format) listings#show_notes
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
listings GET /listings(.:format) listings#index
POST /listings(.:format) listings#create
new_listing GET /listings/new(.:format) listings#new
edit_listing GET /listings/:id/edit(.:format) listings#edit
listing GET /listings/:id(.:format) listings#show
PUT /listings/:id(.:format) listings#update
DELETE /listings/:id(.:format) listings#destroy
root / listings#index
admin_dash_board_index GET /admin_dash_board(.:format) admin_dash_board#index
As you can see there are no routes for the resource :assets.
Any idea why? Or whats going on?
Thanks
I think I found your answer here and here.
Try to add this line in your application.rb:
config.assets.prefix = "/new_route"
EDIT - also here with some other options to solve the problem....