How To: Display a custom sign_in form anywhere in your app
Pages 130
- Home
- Bug reports
- Callbacks
- Contributing
- Customize minimum password length
- Disable password confirmation during registration
- Example applications
- Extensions
- How to : Skip Devise Session Timeout for Other controller actions
- How to manage users with a standard Rails controller
- How to Setup Multiple Devise User Models
- How To: Redirect with locale after authentication failure
- How To: Add :confirmable to Users
- How To: Add :lockable to Users
- How To: Add a default role to a User
- How To: Add an Admin Role
- How To: Add sign_in, sign_out, and sign_up links to your layout template
- How To: Add timeout_in value dynamically
- How To: Allow users to edit their account without providing a password
- How To: Allow users to edit their password
- How To: Allow users to sign in using their username or email address
- How To: Allow users to sign in with something other than their email address
- How To: Allow users to sign_in using their username or email address
- How To: Authenticate via LDAP
- How To: Automatically generate password for users (simpler registration)
- How To: Change an already existing table to add devise required columns
- How To: Change Default Sign_up Registration Path with Custom Path
- How To: Change the default sign_in and sign_out routes
- How To: Change the redirect path after destroying a session i.e. signing out
- How To: Configure a master password
- How to: Confirmable with many email addresses per user
- How To: Create a custom encryptor
- How To: Create a guest user
- How To: Create custom layouts
- How To: Create Haml and Slim Views
- How To: Customize routes to user registration pages
- How To: Customize the redirect after a user edits their profile
- How To: Customize user account status validation when logging in
- How To: Define a different root route for logged in out users
- How To: Define resource actions that require authentication using routes.rb
- How To: Disable user from destroying their account
- How To: Disallow previously used passwords
- How To: Display a custom sign_in form anywhere in your app
- How To: Do not redirect to login page after session timeout
- How To: Email only sign up
- How To: Embed users in your account model with Mongoid
- How To: Find a user when you have their credentials
- How To: Integrate I18n Flash Messages with Devise and Bootstrap
- How To: Integrate with CanCan for roles management
- How to: make Devise work with iOS (for Rails)
- How To: Make Devise work with other formats like mobile, iPhone and iPad Rails specific
- How To: Manage users through a CRUD interface
- How To: Manage Users with an Admin Role (CanCan method)
- How To: Mass password reset and email notification
- How To: Migrate from restful_authentication to Devise
- How To: Migration legacy database
- How To: Not auto sign out after user edit profile
- How To: OmniAuth inside localized scope
- How To: Override build_resource({})
- How To: Override confirmations so users can pick their own passwords as part of confirmation activation
- How To: Protect Resque Web with Devise
- How To: Redirect back to current page after sign in, sign out, sign up, update
- How To: redirect from HTTPS to HTTP on successful sign out
- How To: redirect to a specific page on successful sign in
- How To: Redirect to a specific page on successful sign in sign out
- How To: Redirect to a specific page on successful sign in and sign out
- How To: Redirect to a specific page on successful sign in or sign out
- How To: Redirect to a specific page on successful sign in out
- How To: Redirect to a specific page on successful sign up (registration)
- How To: redirect to a specific page on successful sign_in, sign_out, and or sign_up
- How To: Redirect to a specific page when the user can not be authenticated
- How To: Redirect URL after sending reset password instructions
- How to: Remote authentication with Devise
- How To: request or feature test with Rails 3 (and rspec) for signup
- How To: Require admin to activate account before sign_in
- How To: Require authentication for all pages
- How To: Rspec with devise and machinist
- How to: Scope login to subdomain
- How To: Send devise emails in background (Resque, Sidekiq and Delayed::Job)
- How To: Send emails from subdomains
- How To: Set :host and :port for all devise mailer urls
- How To: Set up devise as a single user system
- How To: Set up simple password complexity requirements
- How To: sign in and out a user in Request type specs (specs tagged with type: :request)
- How To: Sign in as another user if you are an admin
- How To: Sign in from a controller
- How To: Simple Token Authentication Example
- How to: Soft delete a user when user deletes account
- How To: Stub authentication in controller specs
- How To: Test controllers with Rails 3 and 4 (and RSpec)
- How To: Test with Capybara
- How To: Test with Cucumber
- How To: Turn off trackable for admin users
- How To: Two step confirmation
- How To: Upgrade to Devise 2.0
- How To: Upgrade to Devise 2.0 migration schema style
- How To: Upgrade to Devise 2.1
- How To: Upgrade to Devise 2.2
- How To: Upgrade to Devise 3.1
- How To: Upgrade to Devise 4.4.0
- How To: Upgrade: General Instructions
- How to: Use a custom email validator with Devise
- How to: Use cancan devise, the easy way.
- How To: Use case insensitive emails
- How To: Use custom mailer
- How To: Use Devise generated method and filters for controllers
- How To: Use devise inside a mountable engine
- How To: Use HTTP Auth Basic with Devise
- How To: Use HTTP Basic Authentication
- How To: Use Recaptcha with Devise
- How To: Use SSL (HTTPS)
- How To: Use subdomains
- How To: Use with BackboneJS models
- How To: Using ActiveAdmin to login as any user
- How To: Using paranoid mode, avoid user enumeration on registerable
- How to: Write your own serializer
- How To:I18n Message for Scoped Resources
- How Tos
- I18n
- List of Devise Controllers
- Lockdown Username Change
- Notify users via email when their passwords change
- OmniAuth with multiple models
- OmniAuth: Testing
- OmniAuth: Overview
- Omniauthable, sign out action and rememberable
- Override devise_error_messages! for views
- Security Questionaires
- Speed up your unit tests
- Tool: Generate and customize controllers
- Show 115 more pages…
Clone this wiki locally
It’s easy to create a custom login form that can be used anywhere in your application.
Here’s an example in HAML:
= form_tag session_path(:user) do
= text_field_tag 'user[email]'
= password_field_tag 'user[password]'
= check_box_tag 'user[remember_me]'
= label_tag 'user[remember_me]', 'Remember me'
%button Sign in
= link_to "Forgot your password?", new_password_path(:user)
Another example with form_for and posting to user_session_path:
<%= form_for(:user, :url => session_path(:user)) do |f| %>
<%= f.text_field :email %>
<%= f.password_field :password %>
<%= f.check_box :remember_me %>
<%= f.label :remember_me %>
<%= f.submit 'Sign in' %>
<%= link_to "Forgot your password?", new_password_path(:user) %>
<% end %>
Note: “user” in this context is the resource you specified when setting up Devise.
Warning for client_side_validations
Whilst the above method works, it should be noted that using the name of a resource as the first parameter for form_for is now deprecated in Rails. I ran into this problem whilst trying to integrate client_side_validations with devise and it choked on this form. I don’t know if this is the best work around but in the end, I got it working by leaving the devise form_for as it looks normally:
form_for(resource, :as => resource_name ... )
Now the trick is defining those helper methods in other controllers. Assuming your devise model is called “user”, place the following methods either in the helper class of the controller you are using to display the form or in your application helper:
helper_method :resource_name, :resource, :devise_mapping, :resource_class
def resource_name
:user
end
def resource
@resource ||= User.new
end
def resource_class
User
end
def devise_mapping
@devise_mapping ||= Devise.mappings[:user]
end
Another advantage of this method is that you don’t need to alter the default devise forms. Just move them into a partial and render them wherever you want.
Source: http://pupeno.com/blog/show-a-devise-log-in-form-in-another-page/