Devise Custom Routes and Login Pages
With Devise 1.1.3 the following should work
devise_for :user, :path => '', :path_names => { :sign_in => "login", :sign_out => "logout", :sign_up => "register" }
The routes it creates will not be appended with "/user/..." because of the :path
parameter being an empty string. The :pathnames
hash will take care of naming the routes as you like. Devise will use these routes internally so submitting to /login will work as you wish and not take you to /user/log_in
To add a login form to your front page there's info at the Devise Wiki:
http://github.com/plataformatec/devise/wiki/How-To:-Display-a-custom-sign_in-form-anywhere-in-your-app
Or do something like this:
<%= form_tag new_user_session_path do %>
<%= text_field_tag 'user[email]' %>
<%= password_field_tag 'user[password]' %>
<%= submit_tag 'Login' %>
Customize part of devise custom routes, basically I don't know Rails routing =(
You can access specify the route normally as you would do in a rails app. Only thing you need to do is wrap the route inside a device_scope
. This also shows up as warning when you try to access the route without adding the device_scope
.
So in your case routes should be like:
devise_scope :user do
get 'users/sign_up/control' => 'users/registrations#new_control'
get 'users/sign_up/test' => 'users/registrations#new_test'
end
Rails 4 Devise custom routes
There is a typo in your code, a space before 'devise/sessions#new'.
This,
get 'login', to: ' devise/sessions#new', as: :login
should be
get 'login', to: 'devise/sessions#new', as: :login
Devise routes to only use custom sign in page
You may point your root_path
to Devise Sessions controller: "devise/sessions#new" (and move your home view to that page). Also, you may add this line you your routes.
get "/" => "devise/sessions#new", :as => :user_session
Doing this, when a sign in is unsuccessful, you'll be back to the home page (which now is on devise/sessions/new).
Ruby on Rails Routes for custom Devise Signup and Signin forms
From https://github.com/heartcombo/devise#configuring-views:
All you need to do is set config.scoped_views = true inside the config/initializers/devise.rb file.
Devise redirect to custom login page (Regular and Admin Section)
In the application controller place an after_sign_in function as below that would check for the user role and then redirect
class ApplicationController < ActionController::Base
def after_sign_in_path_for(resource)
if resource.is_admin?
redirect_to admin_path
else
redirect_to user_path
end
end
end
Related Topics
How to Use Activerecord in a Ruby Script Outside Rails
Exporting an Environment Variable in Ruby
Ruby Run Shell Command in a Specific Directory
Why Does White-Space Affect Ruby Function Calls
Fork Child Process with Timeout and Capture Output
How to Use the Debugger with Ruby 2.0
Method and Variable Name Is the Same
Rails - Best-Practice: How to Create Dependent Has_One Relations
Why Is Sum So Much Faster Than Inject(:+)
Using Rails Migration on Different Database Than Standard "Production" or "Development"
Double Pipe Symbols in Ruby Variable Assignment
String Interpolation in Ruby Doesn't Work
How to Redirect Stderr and Stdout to File For a Ruby Script
What's the Precedence of Ruby'S Method Call
Can't Install Ruby on Rails with Rvm on Ubuntu 13.04