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

bundleでインストールしたgemの場所を見たり開いたりする

rubyでgemをbundleでインストールした際、gemのソースが見たくなったら

$ bundle show rails
/home/vagrant/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/rails-4.2.0

などと場所がわかります

一気にエディタで開きたかったら

$ bundle open rails

で指定したエディタで開きます

エディタを指定してなければエラーが発生

To open a bundled gem, set $EDITOR or $BUNDLER_EDITOR

そういうときはUbuntuの場合

$ vim ~/.vimrc

EDITOR="vim"

とか書き込んで、設定読み込み

$ source ~/.vimrc

で再度 bundle openしてあげるといいです

gem pgインストール時にエラー

vagrant上のUbuntuでails + postgresqlをインストールしました

事前にpostgresqlをインストール

$ sudo apt-get install postgresql postgresql-contrib

Gemfileに

pg

を追記して

$ bundle install

エラー発生

Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    /home/vagrant/.rbenv/versions/2.2.0/bin/ruby -r ./siteconf20150331-4671-5j34dh.rb extconf.rb 
checking for pg_config... yes
Using config values from /usr/bin/pg_config
You need to install postgresql-server-dev-X.Y for building a server-side extension or libpq-dev for building a client-side application.
You need to install postgresql-server-dev-X.Y for building a server-side extension or libpq-dev for building a client-side application.
checking for libpq-fe.h... no
Can't find the 'libpq-fe.h header
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers.  Check the mkmf.log file for more details.  You may
need configuration options.

Provided configuration options:
        --with-opt-dir
        --without-opt-dir
        --with-opt-include
        --without-opt-include=${opt-dir}/include
        --with-opt-lib
        --without-opt-lib=${opt-dir}/lib
        --with-make-prog
        --without-make-prog
        --srcdir=.
        --curdir
        --ruby=/home/vagrant/.rbenv/versions/2.2.0/bin/$(RUBY_BASE_NAME)
        --with-pg
        --without-pg
        --enable-windows-cross
        --disable-windows-cross
        --with-pg-config
        --without-pg-config
        --with-pg_config
        --without-pg_config
        --with-pg-dir
        --without-pg-dir
        --with-pg-include
        --without-pg-include=${pg-dir}/include
        --with-pg-lib
        --without-pg-lib=${pg-dir}/lib

extconf failed, exit code 1

Gem files will remain installed in /home/vagrant/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/pg-0.18.1 for inspection.
Results logged to /home/vagrant/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/extensions/x86-linux/2.2.0-static/pg-0.18.1/gem_make.out
Installing html2slim 0.2.0
Installing unf 0.1.4
An error occurred while installing pg (0.18.1), and Bundler cannot continue.
Make sure that `gem install pg -v '0.18.1'` succeeds before bundling.

libpq-devが足りなかったみたい

$ sudo apt-get install libpq-dev

で、再度実行でうまくいきました

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