#210 Customizing Devise
Here we dive deeper into Devise by customizing how the views, routing, validations, and authentication works.
- Download:
- source codeProject Files in Zip (164 KB)
- mp4Full Size H.264 Video (13.2 MB)
- m4vSmaller H.264 Video (8.32 MB)
- webmFull Size VP8 Video (23.3 MB)
- ogvFull Size Theora Video (17.4 MB)
Resources
- Devise
- Episode 209: Introducing Devise
- Episode 192: Authorization with CanCan
- Episode 30: Pretty Page Title
- Full episode source code
bash
rails generate devise_views
rails generate migration add_username_to_users username:string
rake db:migrate
rails c
rails generate devise_views rails generate migration add_username_to_users username:string rake db:migrate rails c
projects_controller.rb
before_filter :authenticate_user!, :except => [:show, :index]
before_filter :authenticate_user!, :except => [:show, :index]
routes.rb
devise_for :users, :path_names => { :sign_up => "register" }
devise_for :users, :path_names => { :sign_up => "register" }
config/initializers/devise.rb
config.authentication_keys = [ :username ]
config.password_length = 4..20
config.authentication_keys = [ :username ] config.password_length = 4..20
devise/sessions/new.html.erb
<% title "Sign in" %>
<%= form_for(resource_name, resource, :url => session_path(resource_name)) do |f| %>
<p><%= f.label :username %><br />
<%= f.text_field :username %></p>
<p><%= f.label :password %><br />
<%= f.password_field :password %></p>
<!-- ... -->
<% end %>
<% title "Sign in" %> <%= form_for(resource_name, resource, :url => session_path(resource_name)) do |f| %> <p><%= f.label :username %><br /> <%= f.text_field :username %></p> <p><%= f.label :password %><br /> <%= f.password_field :password %></p> <!-- ... --> <% end %>

