rakeでタスクの一覧を見る

Spreeのときはデフォルトの管理ユーザーを作るのに

$ rake spree_auth:admin:create

を使ったりします
参考: Ruby on RailsにSpreeを入れてみた | bgbgbg

こういったタスクなにがあるんだっけ..?のときに

$ rake -T

とすると一覧で見れて便利です

ちなみに spree を入れた時の結果はこんな感じ

rake assets:clobber                                 # Remove compiled assets
rake assets:environment                             # Load asset compile environment
rake assets:precompile                              # Compile all the assets named in config.assets.precompile
rake cache_digests:dependencies                     # Lookup first-level dependencies for TEMPLATE (like messages/show or comments/_comment.html)
rake cache_digests:nested_dependencies              # Lookup nested dependencies for TEMPLATE (like messages/show or comments/_comment.html)
rake db:bootstrap                                   # Bootstrap is: migrating, loading defaults, sample data and seeding (for all extensions) and load_products tasks
rake db:create                                      # Creates the database from DATABASE_URL or config/database.yml for the current RAILS_ENV (use db:create:all to create all databases in the config)
rake db:drop                                        # Drops the database from DATABASE_URL or config/database.yml for the current RAILS_ENV (use db:drop:all to drop all databases in the config)
rake db:fixtures:load                               # Load fixtures into the current environment's database
rake db:load_dir[dir]                               # Loads fixtures from the the dir you specify using rake db:load_dir[loadfrom]
rake db:load_file[file,dir]                         # Loads a specified fixture file:
rake db:migrate                                     # Migrate the database (options: VERSION=x, VERBOSE=false, SCOPE=blog)
rake db:migrate:status                              # Display status of migrations
rake db:remigrate                                   # Migrate schema to version 0 and back up again
rake db:rollback                                    # Rolls the schema back to the previous version (specify steps w/ STEP=n)
rake db:schema:cache:clear                          # Clear a db/schema_cache.dump file
rake db:schema:cache:dump                           # Create a db/schema_cache.dump file
rake db:schema:dump                                 # Create a db/schema.rb file that is portable against any DB supported by AR
rake db:schema:load                                 # Load a schema.rb file into the database
rake db:seed                                        # Load the seed data from db/seeds.rb
rake db:setup                                       # Create the database, load the schema, and initialize with the seed data (use db:reset to also drop the database first)
rake db:structure:dump                              # Dump the database structure to db/structure.sql
rake db:structure:load                              # Recreate the databases from the structure.sql file
rake db:version                                     # Retrieves the current schema version number
rake deface:clean                                   # Removes all precompiled override templates
rake deface:failures_by_virtual_path[virtual_path]  # Report on failing overrides for a partial/template
rake deface:get_result[virtual_path]                # Get the resulting markup for a partial/template
rake deface:precompile                              # Precompiles overrides into template files
rake deface:test_all                                # Load and apply all overrides, and output results
rake deface:test_selector[virtual_path,selector]    # Applies selectors to given partial/template, and returns match(s) source
rake doc:app                                        # Generate docs for the app -- also available doc:rails, doc:guides (options: TEMPLATE=/rdoc-template.rb, TITLE="Custom Title")
rake email:test                                     # Sends test email to specified address - Example: EMAIL=spree@example.com bundle exec rake test:email
rake exchanges:charge_unreturned_items              # Takes unreturned exchanged items and creates a new order to charge
rake log:clear                                      # Truncates all *.log files in log/ to zero bytes (specify which logs with LOGS=test,development)
rake middleware                                     # Prints out your Rack middleware stack
rake notes                                          # Enumerate all annotations (use notes:optimize, :fixme, :todo for focus)
rake notes:custom                                   # Enumerate a custom annotation, specify with ANNOTATION=CUSTOM
rake paperclip:clean                                # Cleans out invalid attachments
rake paperclip:refresh                              # Refreshes both metadata and thumbnails
rake paperclip:refresh:metadata                     # Regenerates content_type/size metadata for a given CLASS (and optional ATTACHMENT)
rake paperclip:refresh:missing_styles               # Regenerates missing thumbnail styles for all classes using Paperclip
rake paperclip:refresh:thumbnails                   # Regenerates thumbnails for a given CLASS (and optional ATTACHMENT and STYLES splitted by comma)
rake rails:template                                 # Applies the template supplied by LOCATION=(/path/to/template) or URL
rake rails:update                                   # Update configs and some other initially generated files (or use just update:configs or update:bin)
rake routes                                         # Print out all defined routes in match order, with names
rake secret                                         # Generate a cryptographically secure secret key (this is typically used to generate a secret for cookie sessions)
rake spec                                           # Run all specs in spec directory (excluding plugin specs)
rake spec:controllers                               # Run the code examples in spec/controllers
rake spec:helpers                                   # Run the code examples in spec/helpers
rake spree:install:migrations                       # Copy migrations from spree to application
rake spree:reset_taxon_permalinks                   # Resets all taxon permalinks
rake spree_api:install:migrations                   # Copy migrations from spree_api to application
rake spree_auth:admin:create                        # Create admin username and password
rake spree_auth:install:migrations                  # Copy migrations from spree_auth to application
rake spree_i18n:install:migrations                  # Copy migrations from spree_i18n to application
rake spree_paypal_express:install:migrations        # Copy migrations from spree_paypal_express to application
rake spree_sample:load                              # Loads sample data
rake stats                                          # Report code statistics (KLOCs, etc) from the application or engine
rake test                                           # Runs all tests in test folder
rake test:all                                       # Run tests quickly by merging all types and not resetting db
rake test:all:db                                    # Run tests quickly, but also reset db
rake test:db                                        # Run tests quickly, but also reset db
rake time:zones:all                                 # Displays all time zones, also available: time:zones:us, time:zones:local -- filter with OFFSET parameter, e.g., OFFSET=-6
rake tmp:clear                                      # Clear session, cache, and socket files from tmp/ (narrow w/ tmp:sessions:clear, tmp:cache:clear, tmp:sockets:clear)
rake tmp:create                                     # Creates tmp directories for sessions, cache, sockets, and pids

spree 2.6 から 3.0へバージョンアップする

rails 4.1.8 + spree 2.6
でECサイトを作っていましたが、spree 3.0が出てました

https://guides.spreecommerce.com/release_notes/spree_3_0_0.html

  • Bootstrap Backend & Frontend
  • Rails 4.2 Support
  • Google Analytics Enhanced Ecommerce

が主な対応みたいで、上げてみました

https://guides.spreecommerce.com/release_notes/spree_3_0_0.html

を参考に上げてみました
rails 4.2 + spree 最新にします

$ vim Gemfiles

source 'https://rubygems.org'

gem 'rails', '~> 4.2.0'
gem 'mysql2'
gem 'uglifier', '>= 1.3.0'
gem 'jquery-rails'
gem 'turbolinks'
gem 'jbuilder', '~> 2.0'
gem 'sdoc', '~> 0.4.0',          group: :doc
gem 'spring',        group: :development

group :assets do
  gem 'sprockets-rails'
  gem 'sass-rails',   '~> 4.0.0'
  gem 'coffee-rails', '~> 4.0.0'
end

gem 'spree', github: 'spree/spree'
gem 'spree_auth_devise', github: 'spree/spree_auth_devise'
gem 'spree_gateway', github: 'spree/spree_gateway'

で最終的にはこんな形になりました

インストール
$ bundle update
$ bundle install
$ rake railties:install:migrations
$ rake db:migrate

で、あがったようです
bootstrapで見た目も変わりました

Spreeでundefined method `states’ for nil:NilClassのエラーが発生

Ruby on Rails 4.1.8
Spree 2.6-stable
でECサイトを作っていて、カートに商品をいれて次へ進むとエラーが発生

NoMethodError in Spree::Checkout#edit
Showing /home/vagrant/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/bundler/gems/spree-dcd415d3ea99/frontend/app/views/spree/address/_form.html.erb where line #38 raised:
undefined method `states' for nil:NilClass

spree_error

インストールしたばかりなのになぜ..と思ったら

https://github.com/spree/spree/issues/1142
で議論されてましたので参考に

$ rake db:seed

loading ruby /home/vagrant/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/bundler/gems/spree-984ecbce1d91/core/db/default/spree/countries.rb
loading ruby /home/vagrant/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/bundler/gems/spree-984ecbce1d91/core/db/default/spree/roles.rb
loading ruby /home/vagrant/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/bundler/gems/spree-984ecbce1d91/core/db/default/spree/states.rb
loading ruby /home/vagrant/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/bundler/gems/spree-984ecbce1d91/core/db/default/spree/stores.rb
loading ruby /home/vagrant/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/bundler/gems/spree-984ecbce1d91/core/db/default/spree/zones.rb
loading ruby /home/vagrant/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/bundler/gems/spree_auth_devise-0172d0450bef/db/default/users.rb
Admin user has already been previously created.
・・・

などとできあがる初期値を作ってやったら直りました

https://github.com/spree/spree/commit/9820b66bb8d11fc8826dbeead2c46bc1424b8efb
で直ったのかと思ったらだめみたいです

参考) Ruby on RailsにSpreeを入れてみた | bgbgbg