2
Help us understand the problem. What are the problem?

More than 3 years have passed since last update.

posted at

updated at

早くdeviseいれたいねん! ① -- 入門手順で導入してみる --

最低限のコマンドとコードだけをまとめました。(2回目以降の導入に)

もう少し丁寧な導入方法はこちら
初めてのdevise ① -- 導入してみる --

環境

  • Ruby 2.3.3
  • Rails 4.1.16
  • Windows 8 64bit

作業

$ rails new devise
Gemfile
gem 'rails', '4.1.16'
gem 'sqlite3'
gem 'sass-rails', '~> 4.0.3'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.0.0'
gem 'jquery-rails'
gem 'turbolinks'
gem 'jbuilder', '~> 2.0'
gem 'sdoc', '~> 0.4.0',          group: :doc
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw]  #Win 32bitなら :x64_mingwは不要。
gem 'bcrypt-ruby', '~> 3.0.0'          # ←いれないとcannot load such file -- bcrypt_extが発生します。

#↓↓↓以下を追記します↓↓↓
gem 'devise'

$ bundle install
$ rails g devise:install
$ rails g devise User
$ rake db:migrate
$ rails g controller home index
application.html.erb.
<!DOCTYPE html>
<html>
<head>
  <title>Devise</title>
  <%= stylesheet_link_tag    'application', media: 'all', 'data-turbolinks-track' => true %>
  <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
  <%= csrf_meta_tags %>
</head>
<body>

  <!-- ↓↓↓これを追記↓↓↓ -->

  <p class="notice"><%= notice %></p>
  <p class="alert"><%= alert %></p>

  <% if user_signed_in? %>
    ログインユーザー: <%= current_user.email %>
    <%= link_to 'アカウント変更', edit_user_registration_path %>
    <%= link_to "ログアウト", destroy_user_session_path %>
  <% else %>
    <%= link_to "TOP画面", root_path %>
    <%= link_to "新規作成", new_user_registration_path %>
    <%= link_to "ログイン", new_user_session_path %>
  <% end %>

  <!-- ここまで -->

  <%= yield %>

</body>
</html>
routes.rb
Rails.application.routes.draw do

  devise_for :users
  root to: "home#index"

end

動作確認しましょう!

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
2
Help us understand the problem. What are the problem?