4
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

rails devise 設定 備忘録

Posted at

rails 認証機能 設定の備忘録

ex)http://railsgirls.jp/devise/

Rails 3.2.13
CentOS release 5.7 (Final)

Gemfileにdeviseを追加とインストール

$vi Gemfile
$diff Gemfile Gemfile.org
40d39
< gem 'devise'
$bundle install

devise セットアップ

$rails g 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

===============================================================================

環境設定

$vi config/environments/development.rb
$diff development.rb development.rb.org
37,38d36
<
<   config.action_mailer.default_url_options = { :host => 'localhost:3000'}
$vi app/views/layouts/application.html.erb
<p class="notice"><%= notice %></p>
<p class="alert"><%= alert %></p>
を追加

Model をセットアップ

$rails g devise user
$rake db:migrate

ログイン画面

url:http://localhost/user/sigin_in

ログインできる
OK

4
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?