Skip to content

Instantly share code, notes, and snippets.

@fk2000
Last active August 31, 2016 01:20
Show Gist options
  • Save fk2000/66386d32395edc8f171dc5a5dd8b25c5 to your computer and use it in GitHub Desktop.
Save fk2000/66386d32395edc8f171dc5a5dd8b25c5 to your computer and use it in GitHub Desktop.
Rails初心者〜構築からMVC開発〜 ref: http://qiita.com/fk_2000/items/28a1564150eabfd6468b
rubyuser01:~/workspace $ ruby -v
ruby 2.3.0p0 (2015-12-25 revision 53290) [x86_64-linux]
rubyuser01:~/workspace $ rails -v
bash: rails: command not found
rubyuser01:~/workspace/demo $ rails generate controller top index
rubyuser01:~/workspace/demo $ ls -l app/controllers/top_controller.rb
-rw-r--r-- 1 ubuntu ubuntu 66 Aug 30 04:12 app/controllers/top_controller.rb
rubyuser01:~/workspace/demo $ ls -l app/views/top/index.html.erb
-rw-r--r-- 1 ubuntu ubuntu 66 Aug 30 04:12 app/views/top/index.html.erb
rubyuser01:~/workspace/demo $ cat app/controllers/top_controller.rb
class TopController < ApplicationController
def index
end
end
rubyuser01:~/workspace/demo $ cat app/views/top/index.html.erb
<h1>Top#index</h1>
<p>Find me in app/views/top/index.html.erb</p>
rubyuser01:~/workspace/demo $ vi config/routes.rb
Rails.application.routes.draw do
- # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
+ root "top#index"
end
rubyuser01:~/workspace/demo $ cat config/routes.rb
Rails.application.routes.draw do
root "top#index"
end
rubyuser01:~/workspace/demo $
- →app/views/top/index.html.erbの内容を編集して、ブラウザの更新を行うと即座に反映されることを確認
- <p>〜</p>の文言に、「◆」を追加
- →config/routes.rbの「root "top#index”」を「root "top#index2”」に編集して、ブラウザの更新を行うと即座に反映されエラーとなる。
rubyuser01:~/workspace $ cat /etc/os-release
NAME="Ubuntu"
VERSION="14.04.3 LTS, Trusty Tahr"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 14.04.3 LTS"
VERSION_ID="14.04"
HOME_URL="http://www.ubuntu.com/"
SUPPORT_URL="http://help.ubuntu.com/"
BUG_REPORT_URL="http://bugs.launchpad.net/ubuntu/"
- →Controllerのapp/controllers/top_controller.rb のAction(メソッド)「index」を「index2」に編集して、さらにエラーとなる※
rubyuser01:~/workspace $ gem -v
2.5.1
rubyuser01:~/workspace $ gem install rails
Fetching~
Successfully~
:
37 gems installed
rubyuser01:~/workspace $ rails -v
Rails 5.0.0.1
rubyuser01:~/workspace $ rails new demo
create
create README.md
create Rakefile
create config.ru
create .gitignore
create Gemfile
:
Installing web-console 3.3.1
Using rails 5.0.0.1
Installing sass-rails 5.0.6
Bundle complete! 15 Gemfile dependencies, 63 gems now installed.
Use `bundle show [gemname]` to see where a bundled gem is installed.
run bundle exec spring binstub --all
* bin/rake: spring inserted
* bin/rails: spring inserted
rubyuser01:~/workspace $
rubyuser01:~/workspace $ ls -ltr
total 8
-rw-rw-r-- 1 ubuntu ubuntu 948 May 2 10:49 README.md
drwxr-xr-x 12 ubuntu ubuntu 4096 Aug 30 02:12 demo/
rubyuser01:~/workspace $ cd demo/
rubyuser01:~/workspace/demo $ ls -ltr
total 64
-rw-r--r-- 1 ubuntu ubuntu 130 Aug 30 02:10 config.ru
-rw-r--r-- 1 ubuntu ubuntu 227 Aug 30 02:10 Rakefile
-rw-r--r-- 1 ubuntu ubuntu 374 Aug 30 02:10 README.md
-rw-r--r-- 1 ubuntu ubuntu 1729 Aug 30 02:10 Gemfile
drwxr-xr-x 10 ubuntu ubuntu 4096 Aug 30 02:10 app/
drwxr-xr-x 2 ubuntu ubuntu 4096 Aug 30 02:10 db/
drwxr-xr-x 5 ubuntu ubuntu 4096 Aug 30 02:10 config/
drwxr-xr-x 2 ubuntu ubuntu 4096 Aug 30 02:10 log/
drwxr-xr-x 4 ubuntu ubuntu 4096 Aug 30 02:10 lib/
drwxr-xr-x 2 ubuntu ubuntu 4096 Aug 30 02:10 public/
drwxr-xr-x 8 ubuntu ubuntu 4096 Aug 30 02:10 test/
drwxr-xr-x 3 ubuntu ubuntu 4096 Aug 30 02:10 vendor/
drwxr-xr-x 3 ubuntu ubuntu 4096 Aug 30 02:10 tmp/
-rw-r--r-- 1 ubuntu ubuntu 4343 Aug 30 02:12 Gemfile.lock
drwxr-xr-x 2 ubuntu ubuntu 4096 Aug 30 02:12 bin/
rubyuser01:~/workspace/demo $
rubyuser01:~/workspace/demo $ rails server -b 0.0.0.0 -p 8080
=> Booting Puma
=> Rails 5.0.0.1 application starting in development on http://0.0.0.0:8080
=> Run `rails server -h` for more startup options
Puma starting in single mode...
* Version 3.6.0 (ruby 2.3.0-p0), codename: Sleepy Sunday Serenity
* Min threads: 5, max threads: 5
* Environment: development
* Listening on tcp://0.0.0.0:8080
Use Ctrl-C to stop
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment