Solidus2.3.1のインストール。2018-07-19

# 概要
Solidusをインストールします。
Rails自体のインストールは済んでいるものとします。

Getting startedに従い作業します。
https://github.com/solidusio/solidus#getting-started

# 準備
## Imagemagickのインストール
Imagemagickを利用するのでインストールします。

```
% sudo apt-get install imagemagick
```

## fs.inotify.max_user_watches更新
```
FATAL: Listen error: unable to monitor directories for changes.
Visit https://github.com/guard/listen/wiki/Increasing-the-amount-of-inotify-watchers for info on how to fix this.
```

というエラーが出る場合があるので対応しておきます。

Ubuntuで作業していたので以下を実行

```
% echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p
fs.inotify.max_user_watches=524288
fs.inotify.max_user_watches = 524288
```

# gem:solidusのインストール
Gemfileに以下を追記

```
gem 'solidus', '2.3.1'
gem 'solidus_auth_devise'
gem 'deface' # 2.3だとこれも必要な様子
```

bundle実行

```
% bundle install --path vendor/bundle
```

# 各種ファイルの生成とmigrations
## `rails g spree:install`
```
% bundle exec rails g spree:install
Running via Spring preloader in process 11535
      create  config/initializers/spree.rb
      append  public/robots.txt
      create  vendor/assets/javascripts/spree/frontend
      create  vendor/assets/javascripts/spree/backend
      create  vendor/assets/stylesheets/spree/frontend
      create  vendor/assets/stylesheets/spree/backend
      create  vendor/assets/images/spree/frontend
      create  vendor/assets/images/spree/backend
      create  vendor/assets/javascripts/spree/frontend/all.js
      create  vendor/assets/stylesheets/spree/frontend/all.css
      create  vendor/assets/javascripts/spree/backend/all.js
      create  vendor/assets/stylesheets/spree/backend/all.css
      create  app/overrides
      append  db/seeds.rb
     copying  migrations
    creating  database
        rake  db:create
Database 'rails_development' already exists
Database 'rails_test' already exists
     running  migrations
        rake  db:migrate VERBOSE=false
generating cartons
(1ms)
linking inventory units to cartons
(3ms)
     loading  seed data
        rake  db:seed
loading ruby /home/vagrant/solidus-example/vendor/bundle/ruby/2.4.0/gems/solidus_core-2.3.1/db/default/spree/countries.rb
loading ruby /home/vagrant/solidus-example/vendor/bundle/ruby/2.4.0/gems/solidus_core-2.3.1/db/default/spree/refund_reasons.rb
loading ruby /home/vagrant/solidus-example/vendor/bundle/ruby/2.4.0/gems/solidus_core-2.3.1/db/default/spree/return_reasons.rb
loading ruby /home/vagrant/solidus-example/vendor/bundle/ruby/2.4.0/gems/solidus_core-2.3.1/db/default/spree/roles.rb
loading ruby /home/vagrant/solidus-example/vendor/bundle/ruby/2.4.0/gems/solidus_core-2.3.1/db/default/spree/shipping_categories.rb
loading ruby /home/vagrant/solidus-example/vendor/bundle/ruby/2.4.0/gems/solidus_core-2.3.1/db/default/spree/states.rb
loading ruby /home/vagrant/solidus-example/vendor/bundle/ruby/2.4.0/gems/solidus_core-2.3.1/db/default/spree/stock_locations.rb
loading ruby /home/vagrant/solidus-example/vendor/bundle/ruby/2.4.0/gems/solidus_core-2.3.1/db/default/spree/store_credit.rb
loading ruby /home/vagrant/solidus-example/vendor/bundle/ruby/2.4.0/gems/solidus_core-2.3.1/db/default/spree/stores.rb
loading ruby /home/vagrant/solidus-example/vendor/bundle/ruby/2.4.0/gems/solidus_core-2.3.1/db/default/spree/zones.rb
Create the admin user (press enter for defaults).
Email [admin@example.com]:
Password [test123]:
Done!
     loading  sample data
        rake  spree_sample:load
Loaded Payment Methods samples
Loaded Tax Categories samples
Loaded Tax Rates samples
Loaded Shipping Categories samples
Loaded Shipping Methods samples
Loaded Products samples
Loaded Taxonomies samples
Loaded Taxons samples
Loaded Option Types samples
Loaded Option Values samples
Loaded Product Option Types samples
Loaded Product Properties samples
Loaded Variants samples
Loaded Stock samples
Loading images for Ruby on Rails Tote
Loading images for Ruby on Rails Bag
Loading images for Ruby on Rails Baseball Jersey
Loading images for Ruby on Rails Jr. Spaghetti
Loading images for Ruby on Rails Mug
Loading images for Ruby on Rails Ringer T-Shirt
Loading images for Ruby on Rails Stein
Loading images for Apache Baseball Jersey
Loading images for Ruby Baseball Jersey
Loaded Assets samples
Loaded Addresses samples
Loaded Stores samples
Loaded Orders samples
Loaded Payments samples
Loaded Reimbursements samples
      insert  config/routes.rb
**************************************************
We added the following line to your application's config/routes.rb file:

    mount Spree::Core::Engine, at: '/'
**************************************************
Solidus has been installed successfully. You're all ready to go!

Enjoy!
```

## `rails g solidus:auth:install`
```
% bundle exec rails g solidus:auth:install
Running via Spring preloader in process 12824
      create  config/initializers/devise.rb
         run  bundle exec rake railties:install:migrations FROM=solidus_auth_devise from "."
         run  bundle exec rake db:migrate from "."
```

## `rake railties:install:migrations`
```
% bundle exec rake railties:install:migrations
# 出力なし
```

## `rake db:migrate`
```
% bundle exec rake db:migrate
# 出力なし
```

# 確認
## サーバ起動
```
% bundle exec rails s -b 0.0.0.0
=> Booting Puma
=> Rails 5.1.6 application starting in development
=> Run `rails server -h` for more startup options
Puma starting in single mode...
* Version 3.12.0 (ruby 2.4.4-p296), codename: Llamas in Pajamas
* Min threads: 5, max threads: 5
* Environment: development
* Listening on tcp://0.0.0.0:3000
Use Ctrl-C to stop

```

# ユーザ向けページ
http://localhost:3000/

以下のような画面が表示されました

![スクリーンショット 2018-07-20 13.24.03.png](https://qiita-image-store.s3.amazonaws.com/0/3800/be39f856-6448-db71-2732-fe27310d56e5.png)

## 管理画面
http://localhost:3000/admin/login

![スクリーンショット 2018-07-20 13.27.26.png](https://qiita-image-store.s3.amazonaws.com/0/3800/d63c8ebb-03c2-151c-2830-09eed5621b24.png)

`rails g spree:install` で設定したログイン情報でログインする

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

![スクリーンショット 2018-07-20 13.27.49.png](https://qiita-image-store.s3.amazonaws.com/0/3800/56ca5527-ad55-6c24-13fb-12b1ffb1c8b7.png)