rails newã®å 輩ãªã¹ã¹ã¡æé
railsããã¸ã§ã¯ããæ°ãã使ããéã«å®è¡ãããrails newãã®ãªã¹ã¹ã¡æé ããä¼ç¤¾ã®å è¼©ã«æãã¦ããã ããã®ã§ã¡ã¢ã
åæ
æé
railsã¢ããªã±ã¼ã·ã§ã³ç¨ã®ãã£ã¬ã¯ããªã使ããã
â使ãããã£ã¬ã¯ããªã«ç§»å
$ mkdir rails-app-name $ $ cd rails-app-name $ $ pwd /Users/maetoo11/workspace/rails-app-name $ $ ls -l $
railsã¢ããªã±ã¼ã·ã§ã³ç¨ãã£ã¬ã¯ããªã§bundle initãå®è¡ããGemfileã使ããã
$ ruby -v ruby 2.3.0p0 (2015-12-25 revision 53290) [x86_64-darwin15] $ $ bundle init Writing new Gemfile to /Users/maetoo11/workspace/rails-app-name/Gemfile $ $ $ $ ls -l total 8 -rw-r--r-- 1 maetoo11 staff 64 3 3 17:37 Gemfile
Gemfileãç·¨éãã¦railsã®gem ã追å ããã
$ vi Gemfile 1 source 'https://rubygems.org' 2 3 gem 'rails'
bundle installã§Gemfileã§æå®ãããgemã®ã¤ã³ã¹ãã¼ã«ãè¡ãã
ããã§å¤§äºãªãã¨ï¼
--path vendor/bundle
ãæå®ããrailsã¢ããªã±ã¼ã·ã§ã³ç¨ã®ãã£ã¬ã¯ããªé ä¸ã®vendor/bundleãã£ã¬ã¯ããªã«gemãã¤ã³ã¹ãã¼ã«
ããã«ãããgemãrailsããã¸ã§ã¯ãæ¯ã«ç®¡çã§ããï¼ï¼--jobs=4
ãæå®ããã¨bundle installã並åå¦çã§å®è¡ã§ãã
åèï¼Bundlerで並列処理??bundle installを爆速で処理する方法。 - Qiita
$ bundle install --path vendor/bundle --jobs=4 Fetching gem metadata from https://rubygems.org/........... Fetching version metadata from https://rubygems.org/... Fetching dependency metadata from https://rubygems.org/.. Resolving dependencies... Using json 1.8.3 Installing i18n 0.7.0 Installing minitest 5.8.4 Installing rake 10.5.0 Installing builder 3.2.2 ã»ã»ã»ç¥ã»ã»ã» Installing rails 4.2.5.2 Bundle complete! 1 Gemfile dependency, 34 gems now installed. Bundled gems are installed into ./vendor/bundle. $ $ ls -l total 16 -rw-r--r-- 1 maetoo11 staff 63 3 3 17:37 Gemfile -rw-r--r-- 1 maetoo11 staff 2607 3 3 17:40 Gemfile.lock drwxr-xr-x 3 maetoo11 staff 102 3 3 17:40 vendor $ $ # vendor/bundleé ä¸ã«gemãã¤ã³ã¹ãã¼ã«ããã¦ãããã¨ãç¢ºèª $ ls -la vendor/bundle/ruby/2.3.0/gems total 0 drwxr-xr-x 34 maetoo11 staff 1156 3 3 17:40 . drwxr-xr-x 9 maetoo11 staff 306 3 3 17:40 .. drwxr-xr-x 6 maetoo11 staff 204 3 3 17:40 actionmailer-4.2.5.2 drwxr-xr-x 6 maetoo11 staff 204 3 3 17:40 actionpack-4.2.5.2 ã»ã»ã»ç¥ã»ã»ã»
rails newãå®è¡ããéã«ãä»ä¸ãããªãã·ã§ã³ã決ããã
âã¾ãã¯ãã«ãã表示ãã¦ããªãã·ã§ã³ã確èª
$ bundle exec rails new -h Usage: rails new APP_PATH [options] Options: -r, [--ruby=PATH] # Path to the Ruby binary of your choice # Default: /Users/maetoo11/.rbenv/versions/2.3.0/bin/ruby -m, [--template=TEMPLATE] # Path to some application template (can be a filesystem path or URL) [--skip-gemfile], [--no-skip-gemfile] # Don't create a Gemfile -B, [--skip-bundle], [--no-skip-bundle] # Don't run bundle install -G, [--skip-git], [--no-skip-git] # Skip .gitignore file [--skip-keeps], [--no-skip-keeps] # Skip source control .keep files -O, [--skip-active-record], [--no-skip-active-record] # Skip Active Record files -S, [--skip-sprockets], [--no-skip-sprockets] # Skip Sprockets files [--skip-spring], [--no-skip-spring] # Don't install Spring application preloader -d, [--database=DATABASE] # Preconfigure for selected database (options: mysql/oracle/postgresql/sqlite3/frontbase/ibm_db/sqlserver/jdbcmysql/jdbcsqlite3/jdbcpostgresql/jdbc) # Default: sqlite3 -j, [--javascript=JAVASCRIPT] # Preconfigure for selected JavaScript library # Default: jquery -J, [--skip-javascript], [--no-skip-javascript] # Skip JavaScript files [--dev], [--no-dev] # Setup the application with Gemfile pointing to your Rails checkout [--edge], [--no-edge] # Setup the application with Gemfile pointing to Rails repository [--skip-turbolinks], [--no-skip-turbolinks] # Skip turbolinks gem -T, [--skip-test-unit], [--no-skip-test-unit] # Skip Test::Unit files [--rc=RC] # Path to file containing extra configuration options for rails command [--no-rc], [--no-no-rc] # Skip loading of extra configuration options from .railsrc file Runtime options: -f, [--force] # Overwrite files that already exist -p, [--pretend], [--no-pretend] # Run but do not make any changes -q, [--quiet], [--no-quiet] # Suppress status output -s, [--skip], [--no-skip] # Skip files that already exist Rails options: -h, [--help], [--no-help] # Show this help message and quit -v, [--version], [--no-version] # Show Rails version number and quit Description: The 'rails new' command creates a new Rails application with a default directory structure and configuration at the path you specify. You can specify extra command-line arguments to be used every time 'rails new' runs in the .railsrc configuration file in your home directory. Note that the arguments specified in the .railsrc file don't affect the defaults values shown above in this help message. Example: rails new ~/Code/Ruby/weblog This generates a skeletal Rails installation in ~/Code/Ruby/weblog. See the README in the newly created application to get going.
ä»åã¯
- bundle installãé£ã°ã
- DBã«MySQLãæå®
- turbolinksã使ç¨ããªã
- test-unitã使ç¨ããªã
ãæå®ãã¦rails newãå®è¡ããã
2016/12/16 追è¨
Rails5ããã¯
bundle exec rails new -B -d mysql --skip-turbolinks --skip-test.
ãããã§ãã(æªç¢ºèªã§ã)
$ bundle exec rails new -B -d mysql --skip-turbolinks --skip-test-unit . exist create README.rdoc create Rakefile create config.ru create .gitignore conflict Gemfile Overwrite /Users/maetoo11/workspace/rails-app-name/Gemfile? (enter "h" for help) [Ynaqdh] force Gemfile create app ã»ã»ã»ç¥ã»ã»ã» $ $ ls -l total 40 -rw-r--r-- 1 maetoo11 staff 1392 3 3 17:48 Gemfile -rw-r--r-- 1 maetoo11 staff 2607 3 3 17:40 Gemfile.lock -rw-r--r-- 1 maetoo11 staff 478 3 3 17:48 README.rdoc -rw-r--r-- 1 maetoo11 staff 249 3 3 17:48 Rakefile drwxr-xr-x 8 maetoo11 staff 272 3 3 17:48 app drwxr-xr-x 6 maetoo11 staff 204 3 3 17:48 bin drwxr-xr-x 11 maetoo11 staff 374 3 3 17:48 config -rw-r--r-- 1 maetoo11 staff 153 3 3 17:48 config.ru drwxr-xr-x 3 maetoo11 staff 102 3 3 17:48 db drwxr-xr-x 4 maetoo11 staff 136 3 3 17:48 lib drwxr-xr-x 3 maetoo11 staff 102 3 3 17:48 log drwxr-xr-x 7 maetoo11 staff 238 3 3 17:48 public drwxr-xr-x 3 maetoo11 staff 102 3 3 17:48 tmp drwxr-xr-x 4 maetoo11 staff 136 3 3 17:48 vendor
Gemfileãç·¨éããä¸è¦ãªgemã®åé¤ã¨å¿
è¦ãªgemã®è¿½å ãè¡ãã
âä»åã¯éçºã»ãã¹ãç°å¢ã§webrickã§ã¯ãªãthinã使ãããã«ããã(39è¡ç®)
$ vi Gemfile 1 source 'https://rubygems.org' 2 3 4 # Bundle edge Rails instead: gem 'rails', github: 'rails/rails' 5 gem 'rails', '4.2.5.2' 6 # Use mysql as the database for Active Record 7 gem 'mysql2', '>= 0.3.13', '< 0.5' ã»ã»ã»ç¥ã»ã»ã» 35 36 group :development do 37 # Access an IRB console on exception pages or by using <%= console %> in views 38 gem 'web-console', '~> 2.0' 39 gem 'thin' 40 41 # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring 42 gem 'spring' 43 end
vendor/bundleé ä¸ãgitã§ç®¡çããªããã¡ã¤ã«ã«ããããã«ã.gitignoreãç·¨éããã(9è¡ç®)
$ vi .gitignore 1 # See https://help.github.com/articles/ignoring-files for more about ignoring files. 2 # 3 # If you find yourself ignoring temporary files generated by your text editor 4 # or operating system, you probably want to add a global ignore instead: 5 # git config --global core.excludesfile '~/.gitignore_global' 6 7 # Ignore bundler config. 8 /.bundle 9 /vendor/bundle 10 11 # Ignore all logfiles and tempfiles. 12 /log/* 13 !/log/.keep 14 /tmp
bundlerã®è¨å®ã確èªããã
âæåã®bundle installæã«æå®ãããªãã·ã§ã³ãè¨å®ããã¦ããã
â以éããã®ããã¸ã§ã¯ããã£ã¬ã¯ããªã§å®è¡ããbundlerã¯ãã®è¨å®ã使ç¨ããã
$ cat .bundle/config --- BUNDLE_PATH: vendor/bundle BUNDLE_JOBS: 4 BUNDLE_DISABLE_SHARED_GEMS: '1'
bundle installãå®è¡ããã
$ bundle Fetching gem metadata from https://rubygems.org/........... Fetching version metadata from https://rubygems.org/... Fetching dependency metadata from https://rubygems.org/.. Resolving dependencies... Using rake 10.5.0 Using i18n 0.7.0 Using json 1.8.3 Using minitest 5.8.4 ã»ã»ã»ç¥ã»ã»ã» Bundle complete! 11 Gemfile dependencies, 53 gems now installed. Bundled gems are installed into ./vendor/bundle. Post-install message from rdoc: Depending on your version of ruby, you may need to install ruby rdoc/ri data: <= 1.8.6 : unsupported = 1.8.7 : gem install rdoc-data; rdoc-data --install = 1.9.1 : gem install rdoc-data; rdoc-data --install >= 1.9.2 : nothing to do! Yay!
ããã§rails newã®ãªã¹ã¹ã¡æé ã¯çµããã§ãã