· 2 min read

Screencast: Einführung Devise

Download:

Download (32.2 MB, 10:36) Alternative Download fÜr iPod & Apple TV (26.8 MB, 10:36)

Resourcen:

Quellcode:

[bash] bundle install rails generate devise_install rails generate devise User rake db:migrate rake routes [/bash]

[ruby] # Gemfile gem ‘devise’, ‘1.1.rc0’

# config/environments/development.rb config.action_mailer.default_url_options = { :host => ‘localhost:3000’ }

# models/user.rb class User < ActiveRecord::Base # Include default devise modules. Others available are: # :token_authenticatable, :lockable, :timeoutable, :confirmable and :activatable devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable

# Setup accessible (or protected) attributes for your model attr_accessible :email, :password, :password_confirmation end

# migration class DeviseCreateUsers < ActiveRecord::Migration def self.up create_table(:users) do |t| t.database_authenticatable :null => false # t.confirmable t.recoverable t.rememberable t.trackable # t.lockable :lock_strategy => :failed_attempts, :unlock_strategy => :both

t.timestamps end

add_index :users, :email, :unique => true # add_index :users, :confirmation_token, :unique => true add_index :users, :reset_password_token, :unique => true # add_index :users, :unlock_token, :unique => true end

def self.down drop_table :users end end

# migration create_table(:users) do |t| t.database_authenticatable :null => false # t.confirmable t.recoverable t.rememberable t.trackable # t.lockable :lock_strategy => :failed_attempts, :unlock_strategy => :both

t.timestamps end

add_index :users, :email, :unique => true # add_index :users, :confirmation_token, :unique => true add_index :users, :reset_password_token, :unique => true # add_index :users, :unlock_token, :unique => true [/ruby]

[html]

<% if user_signed_in? %> Signed in as <%= current_user.email %>. Not you? <%= link_to “Sign out”, destroy_user_session_path %> <% else %> <%= link_to “Sign up”, new_user_registration_path %> or <%= link_to “sign in”, new_user_session_path %> <% end %>
[/html]

Back to Blog