Posted at

毎度deviceの設定とかめんどいのでテンプレ化

More than 1 year has passed since last update.


はじめに

なんどdeviceの設定をしただろうか。

もう二度と同じことはしたくない。

そんな思いから作りました。


環境

Rails5.0.6

Ruby2.4.0

device4.3.0


テンプレでやったこと


  • deviseの基本

  • ユーザーネーム追加

  • viewsカスタマイズ

  • 日本語化


ソース

https://github.com/manzen/rails-device


使い方

1 プロジェクトをclone

2 プロジェクト名を変更

3 application.rbを修正


config/application.rb

require_relative 'boot'

require 'rails/all'

# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups)

module RailsDevice # ←ここを任意のプロジェクト名へ
class Application < Rails::Application
# Settings in config/environments/* take precedence over those specified here.
# Application configuration should go into files in config/initializers
# -- all .rb files in that directory are automatically loaded.
end
end


4 session_store.rbを修正


config/initializers/session_store.rb

# Be sure to restart your server when you modify this file.

Rails.application.config.session_store :cookie_store, key: '_rails-device_session'# アプリ名の部分を変更


5 database.ymlを修正


config/database.yml

# MySQL. Versions 5.0 and up are supported.

#
# Install the MySQL driver
# gem install mysql2
#
# Ensure the MySQL gem is defined in your Gemfile
# gem 'mysql2'
#
# And be sure to use new-style password hashing:
# http://dev.mysql.com/doc/refman/5.7/en/old-client.html
#
default: &default
adapter: mysql2
encoding: utf8
pool: 5
username: root
password:
host: localhost

development:
<<: *default
database: rails-device_development # アプリ名の部分を変更する

# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
<<: *default
database: rails-device_test # アプリ名の部分を変更する

# As with config/secrets.yml, you never want to store sensitive information,
# like your database password, in your source code. If your source code is
# ever seen by anyone, they now have access to your database.
#
# Instead, provide the password as a unix environment variable when you boot
# the app. Read http://guides.rubyonrails.org/configuring.html#configuring-a-database
# for a full rundown on how to provide these environment variables in a
# production deployment.
#
# On Heroku and other platform providers, you may have a full connection URL
# available as an environment variable. For example:
#
# DATABASE_URL="mysql2://myuser:mypass@localhost/somedatabase"
#
# You can use this database configuration with:
#
# production:
# url: <%= ENV['DATABASE_URL'] %>
#
production:
<<: *default
database: rails-device_production # アプリ名の部分を変更する
username: rails-device # アプリ名の部分を変更する
password: <%= ENV['RAILS-DEVICE_DATABASE_PASSWORD'] # アプリ名の部分を変更する%>


6 rails s

7 http://localhost:3000/users/sign_up へアクセス


最後に

誤りや、追加の要望があればコメントいただけると嬉しいです。