Home » gem » devise導入と日本語化 (rails)

devise導入と日本語化 (rails)

devise導入

必要なgemを記載していきます:

gem 'devise'
gem 'devise-bootstrap-views'
gem 'devise-i18n'
gem 'devise-i18n-views'

deviseをrailsにインストールしていきます:

$ 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', port: 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:

       

<%= notice %>

       

<%= alert %>


  4. You can copy Devise views (for customization) to your app by running:

       rails g devise:views

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

ユーザーの情報を保存するためのユーザーモデルを作ります:

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

deviseに関するビューを生成します:

$ rails generate devise:views
      invoke  Devise::Generators::SharedViewsGenerator
      create    /views/devise/shared
      create    /views/devise/shared/_links.html.erb
      invoke  form_for
      create    /views/devise/confirmations
      create    /views/devise/confirmations/new.html.erb
      create    /views/devise/passwords
      create    /views/devise/passwords/edit.html.erb
      create    /views/devise/passwords/new.html.erb
      create    /views/devise/registrations
      create    /views/devise/registrations/edit.html.erb
      create    /views/devise/registrations/new.html.erb
      create    /views/devise/sessions
      create    /views/devise/sessions/new.html.erb
      create    /views/devise/unlocks
      create    /views/devise/unlocks/new.html.erb
      invoke  erb
      create    /views/devise/mailer
      create    /views/devise/mailer/confirmation_instructions.html.erb
      create    /views/devise/mailer/password_change.html.erb
      create    /views/devise/mailer/reset_password_instructions.html.erb
      create    /views/devise/mailer/unlock_instructions.html.erb

 

deviseを日本語化にする

日本語翻訳ファイルを生成します:

$ rails generate devise:views:locale ja
      create  config/locales/devise.views.ja.yml

英語の翻訳を日本語の翻訳にする:

# 日本語設定にする
# config.i18n.default_locale = :de が既に存在する場合は [de] を [ja]にする
config.i18n.default_locale = :ja

deviseのビューが日本語になると思います


追記

  • deviseのデザインは、bootstrapではデザイン専用のgemもあります。その他にもデザインのフレームワークなどもありますので好みで。
, , ,

コメントを残す

%d人のブロガーが「いいね」をつけました。