Rails 5ã®ç°å¢æ§ç¯ï¼ç¶ãï¼
ãååã¯Rails 5ã®ã¤ã³ã¹ãã¼ã«ã¾ã§ãè¡ãã¾ããã
ãä»åã¯Railsããã¸ã§ã¯ãã®ä½æã¨ãã¼ã¿ãã¼ã¹ä½æãpumaãµã¼ãã¼ã®èµ·åãè¡ãã¾ãã
Railsããã¸ã§ã¯ãã®ä½æ
ãRailsããã¸ã§ã¯ããä½æãã¾ãã
ãRailsã®ããã©ã«ãã®ãã¼ã¿ãã¼ã¹ã¯SQLiteã§ãããæ¬é£è¼ã§ã¯ãã¼ã¿ãã¼ã¹ã«PostgreSQLã使ç¨ããããã-d postgresãªãã·ã§ã³ãæå®ãã¾ãã
$ bundle exec rails new . -d postgresql exist create README.md create Rakefile create config.ru create .gitignore conflict Gemfile Overwrite /Users/chikuba/sandbox/rails/rails5_sample/Gemfile? (enter "h" for help) [Ynaqdh]â ï¼ãYãã¨å ¥åï¼ force Gemfile create app create app/assets/config/manifest.js â¦ï¼ä¸ç¥ï¼â¦ Installing sass-rails 5.0.6 Bundle complete! 15 Gemfile dependencies, 63 gems now installed. Bundled gems are installed into ./vendor/bundle. run bundle exec spring binstub --all * bin/rake: spring inserted * bin/rails: spring inserted
ãrails newã³ãã³ãã§ã¯Gemfileãçæãã¾ãããæ¢ã«bundle initã«ãã£ã¦çæãããGemfileãåå¨ãã¦ãããããä¸æ¸ããããèãã¦ãã¾ããããã§ã¯ä¸æ¸ããããããYãå ¥åãã¾ãã
ããã®ããã«ãä¸éãRailsã§å¿ è¦ã¨ãªããã¡ã¤ã«ç¾¤ãçæãããå¾ãããã©ã«ãã§ã¯èªåã§bundle installãå®è¡ããã¾ããããã¯Gemfileãrails newã³ãã³ãã«ãã£ã¦ä¸æ¸ãããã追å ã§å®ç¾©ãããgemããã±ã¼ã¸ã®ã¤ã³ã¹ãã¼ã«ãå¿ è¦ãªããã§ããbundle installãæåã§è¡ãããå ´åã¯--skip-bundleãªãã·ã§ã³ãæå®ãã¾ãã
ãå®éã«rails newã³ãã³ãã§åçæãããGemfileã®ä¸èº«ã¯ã以ä¸ã®éãã§ãã
source 'https://rubygems.org' # Bundle edge Rails instead: gem 'rails', github: 'rails/rails' gem 'rails', '~> 5.0.0', '>= 5.0.0.1' # Use postgresql as the database for Active Record gem 'pg', '~> 0.18' # Use Puma as the app server gem 'puma', '~> 3.0' # Use SCSS for stylesheets gem 'sass-rails', '~> 5.0' â¦ï¼ä¸ç¥ï¼â¦ # Windows does not include zoneinfo files, so bundle the tzinfo-data gem gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
ã-d postgresqlãªãã·ã§ã³ãæå®ããã®ã§ãGemfileã®éãããã¼ã¿ãã¼ã¹ã¢ããã¿ã¼ã®gemãpgã¨ãªã£ã¦ãã¾ãããã®ãªãã·ã§ã³ããªãã¨ããã©ã«ãã§ã¯gem sqlite3ã¨ãªãã¾ãã
ãã¼ã¿ãã¼ã¹æ¥ç¶ã®è¨å®
ãRailsã¢ããªã±ã¼ã·ã§ã³ã使ç¨ãããã¼ã¿ãã¼ã¹ã®è¨å®ã確èªãã¾ãããã¼ã¿ãã¼ã¹ã®è¨å®ãã¡ã¤ã«ã¯config/databases.ymlã§ãã
default: &default adapter: postgresql encoding: unicode â¦ä¸ç¥â¦ pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> development: <<: *default database: rails5_sample_development â¦ä¸ç¥â¦ test: <<: *default database: rails5_sample_test â¦ä¸ç¥â¦ production: <<: *default database: rails5_sample_production username: rails5_sample password: <%= ENV['RAILS5_SAMPLE_DATABASE_PASSWORD'] %>
ããã®ããã«ãããã©ã«ãã§ã¯éçºç°å¢ç¨ï¼developmentï¼ããã¹ãç°å¢ç¨ï¼testï¼ãæ¬çªç°å¢ç¨ï¼productionï¼ã®ãã¼ã¿ãã¼ã¹åã®è¨å®ãå ¥ã£ã¦ãã¾ãããã¼ã¿ãã¼ã¹ã®ãã¹ãã¯localhostããã¼ãçªå·ã¯5432ããããããããã©ã«ãå¤ã§ãã
ããã¼ã¿ãã¼ã¹åã¯ããã¸ã§ã¯ãå_ç°å¢ã¨ãç°å¢ã®ãã¹ããã£ãã¯ã¹ãä»ãã¦ãããã¨ãåããã¾ãã
ãconfig/databases.ymlã®encodingãããã©ã«ãã§unicodeã«ãªã£ã¦ãã¾ãã®ã§ããããutf8ã«å¤æ´ãã¾ãã
default: &default adapter: postgresql encoding: utf8 â¦ä¸ç¥â¦
ããªãããã¼ã«ã«PCã¸ã®PostgreSQLã¤ã³ã¹ãã¼ã«æãç¹ã«ãªãã·ã§ã³çãæå®ãã¦ããªããã°ãã°ã¤ã³ã¦ã¼ã¶ã¼ã§ãã¹ã¯ã¼ããªãã®ãã¼ã¿ãã¼ã¹ä½æ権éãä»ä¸ããã¦ããã¯ããªã®ã§ãconfig/databases.ymlã®usernameãpasswordã¯æå®ãªãã§ãåé¡ããã¾ããã
ãã²ã¨ã¾ãã¯éçºç°å¢ï¼ãã¹ãç°å¢ç¨ã®ãã¼ã¿ãã¼ã¹ãRailsçµç±ã§ä½æãã¾ãããã以ä¸ã®ã³ãã³ããå®è¡ãã¾ãã
$ bundle exec rails db:create Created database 'rails5_sample_development' Created database 'rails5_sample_test'
ã以åã¯rakeã³ãã³ãã§å®è¡ãã¦ãã¾ããããRails 5ã§ã¯railsã³ãã³ãã§ãã¼ã¿ãã¼ã¹ãä½æãããã¨ãã§ããããã«ãªãã¾ãããã¾ãã以åã¯ãã¼ã¿ãã¼ã¹ä½æãããã¡ãã»ã¼ã¸ãåºåããã¾ããã§ããããã¡ãã»ã¼ã¸ãåºåãããããã«ãªã£ã¦ãã¾ãã
Railsã¢ããªã±ã¼ã·ã§ã³ã®èµ·å
ãããããRailsã¢ããªã±ã¼ã·ã§ã³ã®èµ·åã§ãã
ãrails sã³ãã³ãã§Railsã¢ããªã±ã¼ã·ã§ã³ãèµ·åãã¦ã¿ã¾ãããã
$ bundle exec rails s => Booting Puma => Rails 5.0.0.1 application starting in development on http://localhost:3000 => Run `rails server -h` for more startup options Puma starting in single mode... * Version 3.6.0 (ruby 2.3.1-p112), codename: Sleepy Sunday Serenity * Min threads: 5, max threads: 5 * Environment: development * Listening on tcp://localhost:3000 Use Ctrl-C to stop
ãç¡äºã«Webãµã¼ãã¼ã®Pumaãèµ·åãã¾ããã
ãåå触ããããã«ãRailsã®ããã©ã«ãã®Webãµã¼ãã¼ãWEBrickããPumaã«å¤æ´ããã¦ãã¾ãã
ãWebãµã¼ãã¼ãèµ·åããã®ã§Webãã©ã¦ã¶ã§ãhttp://localhost:3000ãã«ã¢ã¯ã»ã¹ãã¾ãã以ä¸ã®ãããªç»é¢ãåºåãããã°ç¡äºãRails 5ã®éçºç°å¢ãæ´ãã¾ããã
ãRailsã¢ããªã±ã¼ã·ã§ã³ãèµ·åããã³ã³ã½ã¼ã«ã«æ»ãã¨ã以ä¸ã®ãããªãã°ãåºåããã¦ãããã¨ã確èªã§ãã¾ãã
Started GET "/" for ::1 at 2016-09-04 02:36:08 +0900 Processing by Rails::WelcomeController#index as HTML Parameters: {"internal"=>true} Rendering vendor/bundle/ruby/2.3.0/gems/railties-5.0.0.1/lib/rails/templates/rails/welcome/index.html.erb Rendered vendor/bundle/ruby/2.3.0/gems/railties-5.0.0.1/lib/rails/templates/rails/welcome/index.html.erb (5.2ms) Completed 200 OK in 30ms (Views: 14.3ms | ActiveRecord: 0.0ms)