rails gem的实现模式( implementation for rails gem)

访问量: 1230

最典型的要数: devise.

1. 初始化配置文件

$ bundle exec rails generate devise:install
      create  config/initializers/devise.rb
      create  config/locales/devise.en.yml

Some setup you must do manually if you haven't yet:
  1. Ensure you have defined default url options in your environments files. Here 
     is an example of default_url_options appropriate for a development environment 
     in config/environments/development.rb:
       config.action_mailer.default_url_options = { :host => 'localhost:3000' }
     In production, :host should be set to the actual host of your application.

  2. Ensure you have defined root_url to *something* in your config/routes.rb.
     For example:
       root :to => "home#index"

  3. Ensure you have flash messages in app/views/layouts/application.html.erb.
     For example:
       <p class="notice"><%= notice %></p>
       <p class="alert"><%= alert %></p>

  4. If you are deploying on Heroku with Rails 3.2 only, you may want to set:
       config.assets.initialize_on_precompile = false
     On config/application.rb forcing your application to not access the DB
     or load models when precompiling your assets.

  5. You can copy Devise views (for customization) to your app by running:
       rails g devise:views

2. generate model:

$ bundle exec rails generate devise user
      invoke  active_record
      create    db/migrate/20140130232140_devise_create_users.rb
      create    app/models/user.rb
      invoke    rspec
      create      spec/models/user_spec.rb
      invoke      factory_girl
      create        spec/factories/users.rb
      insert    app/models/user.rb
       route  devise_for :users

3. its model:

class User < ActiveRecord::Base
  # Include default devise modules. Others available are:
  # :token_authenticatable, :confirmable,
  # :lockable, :timeoutable and :omniauthable
  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable, :confirmable
end

订阅/RSS Feed

Subscribe

分类/category