LoginSignup
2
2

More than 5 years have passed since last update.

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

Last updated at Posted at 2017-06-16

最低限のコマンドとコードだけをまとめました。(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

動作確認しましょう!

2
2
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
2
2