I am using devise for user registration but i am facing a problem where when i submit the signup form i get redirected to /users but i want to stay on /signup where the registration form is...
I achieved it but now i cant see any error messages
my starting form open code
<%= form_for(resource, :as => resource_name, :url => signup_path) do |f| %>
routes
devise_scope :user do
get "signup", :to => "devise/registrations#new"
post "signup", :to => "devise/registrations#new"
end
Your post route should point to "devise/registrations#create"
Related
I want to disable user registration path and keep user edit path. I used this guide for devise Solution 2.
But I am getting this error
ActionController::UnknownFormat at /users.55840776527573104d0c0000
ActionController::UnknownFormat
The form generates incorrect url, it should be like that
/users/55840776527573104d0c0000
View
<%= form_for(resource, as: resource_name, url: user_registration_path(resource), html: { method: :patch}) do |f| %>
<%= f.submit "Update"%>
routes.rb
devise_for :users, :skip => [:registrations]
as :user do
get 'users/edit' => 'devise/registrations#edit', :as => 'edit_user_registration'
patch'users' => 'devise/registrations#update', :as => 'user_registration'
end
How to fix it?
Solution for this problem is to add :id into routes.rb - patch
devise_for :users, :skip => [:registrations]
as :user do
get 'users/edit' => 'devise/registrations#edit', :as => 'edit_user_registration'
patch'users/:id' => 'devise/registrations#update', :as => 'user_registration'
end
Found solution here
I have a settings tab which links to the user to edit_user_registrations_path corresponding to the devise/registrations/edit.html.erb page.
I created another page under devise/registrations called edit_account.html.erb and I'd like this to allow the user to edit additional settings like Twitter and any other social networks that allow it.
I keep getting a routing error. This is the route I tried using with no luck:
devise_scope :user do get "/edit/edit_account" => "devise/registrations#edit_account" end
Thanks in advance!
The way I do it in my routes file is like this:
devise_scope :user do
put "edit/edit_account", :to => "devise/registrations#edit_account",
:as => "edit_account"
end
and then like this:
<%= simple_form_for(resource, :as => resource_name, :url => edit_account_path(resource_name), :html => { :method => :put }) do |f| %>
I'm trying to implement a Twitter Boostrap login form, that's gonna be used on every page (because the navigation bar is a part of the layout).
However, when trying the code below I get the following error:
No route matches {:action=>"show", :controller=>"users"}
User controller:
class UsersController < ApplicationController
def index
#users = User.all
end
def show
...
end
def login
...
end
end
_navigation.html.erb:
<div class="dropdown-menu" style="padding: 15px; padding-bottom: 0px;">
<%= form_for("user", :url => user_path) do |f| %>
<%= f.label :email%>
<%= f.text_field(:email, :size => 30, :class => 'login_field', :placeholder => 'Användarnamn')%>
<%= f.label :password%>
<%= f.text_field(:password, :size => 30, :class => 'login_field', :placeholder => 'Lösenord')%>
<%= f.submit "Logga in", :class => 'login_submit btn btn-primary' %>
<% end %>
</div>
config/routes.rb:
get "home/index"
resources :users
resources :projects
resources :tickets
root :to => 'home#index'
rake routes (that has to do with users):
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
I'm new to Rails but find it strange that it complains that the route doesn't exist because the action "show" is to be found inside the user controller.
The other thing I'm wondering about is why it looks for the action "show", while it should be "login" in this case?
Why is this happening and what shall I do?
your error is in this line
<%= form_for("user", :url => user_path) do |f| %>
user_path is expecting an id. if you change that to users_path, that should fix it but I don't think that's your intention.
UPDATE: to use the login action on the users controller, you need to update your routes
resources :users do
post :login, on: :collection, as: :login
end
passing the :as option creates a named_route for you called login_users_path which you can use on your form_for. and since we wanted to do a post, we also need to specify that in the form_for
<%= form_for("user", :url => login_users_path, :html => { :method => :post }) do |f| %>
Update your routes.rb to look like:
get "home/index"
resources :users do
post :login, :on => :collection
end
resources :projects
resources :tickets
root :to => 'home#index'
and in your view file change the form_for line to be:
<%= form_for("user", :url => login_users_path) do |f| %>
resources :users only adds default routes. If you want to add new action (other then defaults) you need to use 'collection. And you can specify the method get or post. After adding to routes.rb. You can get the path by running rake routes then you add the correct route in the action of form.
resources :users, :collection => {:login => :post}
How to use another page(not defaule) to edit user (Devise gem) ?
I have this situation: I need some page to add attributes to user, but I want to use edit_user_registration - I want to use another page.
So I need to create another action in registrations controller and add it in routes.rb. Also I created another file in registrations folder, but I have troubles with implementation.
Here is my registrations controller:
def paypal
end
and paypal.html.erb:
<%= form_for(resource, :as => resource_name, :url => registration_path(resource_name), :html => { :method => :put }) do |d| %>
<%= d.email_field :paypal_email %>
...
<%end%>
Question: what I should write in my routes rb to call paypal action and edit page worked properly?
devise_for :users, :controllers => {:registrations => 'registrations', :sessions => 'sessions'} do
registrations#paypal//something here instead
end
I'm adding a nav menu in application.html.erb which navigate users in authlogic. All routers like: :logout, :register and :login seems working with custom paths.
match 'account/login' => 'user_sessions#new', :as => :login
match 'account/logout' => 'user_sessions#destroy', :as => :logout
match 'register' => 'users#new', :as => :register
Here is nav menu:
<% if current_user %>
<%= link_to "Edit Profile", edit_user_path(current_user.id)%> <%=h current_user.firstname %>
<%= link_to "Logout", :logout %>
<% else %>
<%= link_to "Register", :register %> |
<%= link_to "Login", :login %>
<% end %>
But edit_user_path is transferring me to /users/:id/edit. How do I make the nice URL for this path. I would like to make it /account/edit. It also need to disable this path /users/:id/edit to prevent user from requesting another user ID which doesnt belong to him/her. It should throw a 404 page is perfect.
Current paths in the nav menu:
Logout: /account/logout
Login: /account/login
Register: /register
I would love to have another path for edit_user_path:
Edit profile: /account/edit
Is there any way I can simply use edit_user_path(current_user.id) and the path automatically transfers me to /account/edit and disable id request.
Any help would be much appreciated! Thanks!
[Updated] This is my /config/router.rb
Appcatous::Application.routes.draw do
resources :users, :user_sessions
match "account" => "users#show", :as => :account
match 'account/login' => 'user_sessions#new', :as => :login
match 'account/logout' => 'user_sessions#destroy', :as => :logout
end
users.rb model is very simple:
class User < ActiveRecord::Base
acts_as_authentic
validates :firstname, :presence => true
validates :lastname, :presence => true
end
It would be helpful if you included all the routes in question - which means also the routes for the users. Did you create those with:
resources :users
In case you did, you'll have to disable that command and recreate just the routes you need manually with (example!):
match 'account/edit' => 'users#edit', :as => :edit_user
or whatever your controller is named. That way you'll get your "/account/edit" - however, you'll also have no way to transfer the user id that way. That one you'll have to transfer by other means, like through a variable stored in a cookie or a session.
The latter method is the usual way of remembering user authentification anyway.