LoginSignup
4
7

More than 5 years have passed since last update.

spree3.0 インストールメモ

Last updated at Posted at 2015-11-11

「Spree is dead.」
なんて言われてますが、railsでECならSpreeかなということでインストールしてみました。
https://github.com/spree/spree

環境

Ruby 2.2.2
Rails 4.2.4

spree3.0のstableのインストール

gem 'spree', github: 'spree/spree', branch: '3-0-stable'
bundle install

インストールジェネレータを設定
rails g spree:install --sample=false --seed=false

以下のエラーが出た

rescue in spec': Specified 'mysql2' for database adapter, but the gem is not loaded. Add gem 'mysql2' to your Gemfile (and ensure its version is at the minimum required by ActiveRecord). (Gem::LoadError)

DBの作成して再度実行
rake db:create
rails g spree:install --sample=false --seed=false

Spree has been installed successfully. You're all ready to go!
Enjoy!

そして次のコマンドを実行
bundle exec rake railties:install:migrations
bundle exec rake db:migrate
bundle exec rake db:seed
bundle exec rake spree_sample:load

サーバ立ち上げ

rails s
ブラウザで次のURLを確認 http://localhost:3000
スクリーンショット 2015-11-11 12.35.12.png

認証機能を追加

gem 'spree_auth_devise', github: 'spree/spree_auth_devise', branch: '3-0-stable'
bundle install
bundle exec rake spree_auth:install:migrations
bundle exec rake db:migrate

config/initializers/spree.rbを編集
Spree.user_class = 'Spree::LegacyUser'
から
Spree.user_class = 'Spree::User'
へ

bundle exec rake spree_auth:admin:create
とりあえず初期設定でadminユーザを作成

Create the admin user (press enter for defaults).
Email [spree@example.com]:
Password [spree123]:
Done!
Done!

管理画面

ブラウザで次のURLを確認 http://localhost:3000/admin
スクリーンショット 2015-11-11 12.55.02.png
先ほどのadminユーザでログイン
スクリーンショット 2015-11-11 12.56.27.png
管理画面が確認できた。

国際化対応

gem 'spree_i18n', github: 'spree-contrib/spree_i18n', branch: '3-0-stable'
bundle install
rails g spree_i18n:install

Adminユーザで再度ログインすると
[CONFIGURATIONS]-[General Settings]-[Localization Settings]
が増えている。
[AVAILABLE LOCALES]に”日本語(ja~JP)(ja)“を追加してUpdate

その後、再度[Localization Settings]を開き、[SUPPORTED LOCALES]に
”日本語(ja~JP)(ja)“を追加してもう一度Update

application.rbに以下を追加
config.i18n.default_locale = :ja

そしてRailsを再起動
rails s

ちなみに英語と日本語の2つに対応したかったので、この方法です。
日本語だけでいい方は、[SUPPORTED LOCALES]を日本語だけにすると良いと思います.

こんな感じで右上にロケールを選択できるプルダウンができました。
スクリーンショット 2015-11-11 16.37.25.png

アパッチ野球ジャージ(笑

4
7
1

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
7