갈루아의 반서재

728x90



1. Requirements


Rails 어플리케이션에 대한 기초가 없는 초보자를 위한 가이드입니다. 필수 설치프로그램은 다음과 같습니다.


상기 언급된 프로그램을 다음과 같이 설치합니다. 

1) Ruby 2.2.3 설치

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
(envruby) root@localhost:~# conda install -c bioconda ruby=2.2.3
Fetching package metadata ...........
Solving package specifications: .
 
Package plan for installation in environment /root/anaconda/envs/envruby:
 
The following NEW packages will be INSTALLED:
 
    gmp:      6.1.0-0
    jemalloc: 4.5.0-0 bioconda
    ruby:     2.2.3-0 bioconda
 
Proceed ([y]/n)? y
 
gmp-6.1.0-0.ta 100% |################################| Time: 0:00:00  14.68 MB/s
jemalloc-4.5.0 100% |################################| Time: 0:01:06  97.40 kB/s
ruby-2.2.3-0.t 100% |################################| Time: 0:08:58  45.96 kB/s
cs


2) SQLite3 설치

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
(envruby) root@localhost:~# sudo apt-get install sqlite3 libsqlite3-dev
패키지 목록을 읽는 중입니다... 완료
의존성 트리를 만드는 중입니다
상태 정보를 읽는 중입니다... 완료
제안하는 패키지:
  sqlite3-doc
다음 새 패키지를 설치할 것입니다:
  libsqlite3-dev sqlite3
0개 업그레이드, 2개 새로 설치, 0개 제거 및 96개 업그레이드 안 함.
467 k바이트 아카이브를 받아야 합니다.
이 작업 후 1,656 k바이트의 디스크 공간을 더 사용하게 됩니다.
받기:1 http://kr.archive.ubuntu.com/ubuntu/ trusty-updates/main libsqlite3-dev amd64 3.8.2-1ubuntu2.1 [439 kB]
받기:2 http://kr.archive.ubuntu.com/ubuntu/ trusty-updates/main sqlite3 amd64 3.8.2-1ubuntu2.1 [28.8 kB]
내려받기 467 k바이트, 소요시간 1초 (416 k바이트/초)
Selecting previously unselected package libsqlite3-dev:amd64.
(데이터베이스 읽는중 ...현재 134729개의 파일과 디렉터리가 설치되어 있습니다.)
Preparing to unpack .../libsqlite3-dev_3.8.2-1ubuntu2.1_amd64.deb ...
Unpacking libsqlite3-dev:amd64 (3.8.2-1ubuntu2.1) ...
Selecting previously unselected package sqlite3.
Preparing to unpack .../sqlite3_3.8.2-1ubuntu2.1_amd64.deb ...
Unpacking sqlite3 (3.8.2-1ubuntu2.1) ...
Processing triggers for man-db (2.6.7.1-1ubuntu1) ...
libsqlite3-dev:amd64 (3.8.2-1ubuntu2.1) 설정하는 중입니다 ...
sqlite3 (3.8.2-1ubuntu2.1) 설정하는 중입니다 ...
cs



2. Installing Rails

1.에서 설치한 프로그램의 버전을 확인한 후  gem install을 이용하여 rails 를 설치한다.


1
2
3
4
5
6
(envruby) root@localhost:~# ruby -v
ruby 2.2.3p173 (2015-08-18 revision 51636) [x86_64-linux]
(envruby) root@localhost:~# sqlite3 --version
3.13.0 2016-05-18 10:57:30 fc49f556e48970561d7ab6a2f24fdd7d9eb81ff2
(envruby) root@localhost:~# gem install rails
36 gems installed
cs


3. Creating the Blog Application


1) 제너레이터를 이용하여 다음과 같이 blog 디렉토리에 blog 라는 이름을 가진 Rails 어플리케이션을 생성한다.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
(envruby) root@localhost:~# rails new blog
      create
      create  README.md
      create  Rakefile
      create  config.ru
      create  .gitignore
      create  Gemfile
         run  git init from "."
초기화: 빈 깃 저장소, 위치 /root/blog/.git/
      create  app
      create  app/assets/config/manifest.js
      create  app/assets/javascripts/application.js
      create  app/assets/javascripts/cable.js
      create  app/assets/stylesheets/application.css
      create  app/channels/application_cable/channel.rb
      create  app/channels/application_cable/connection.rb
      create  app/controllers/application_controller.rb
      create  app/helpers/application_helper.rb
      create  app/jobs/application_job.rb
      create  app/mailers/application_mailer.rb
      create  app/models/application_record.rb
      create  app/views/layouts/application.html.erb
      create  app/views/layouts/mailer.html.erb
      create  app/views/layouts/mailer.text.erb
      create  app/assets/images/.keep
      create  app/assets/javascripts/channels
      create  app/assets/javascripts/channels/.keep
      create  app/controllers/concerns/.keep
      create  app/models/concerns/.keep
      create  bin
      create  bin/bundle
      create  bin/rails
      create  bin/rake
      create  bin/setup
      create  bin/update
      create  bin/yarn
      create  config
      create  config/routes.rb
      create  config/application.rb
      create  config/environment.rb
      create  config/secrets.yml
      create  config/cable.yml
      create  config/puma.rb
      create  config/spring.rb
      create  config/environments
      create  config/environments/development.rb
      create  config/environments/production.rb
      create  config/environments/test.rb
      create  config/initializers
      create  config/initializers/application_controller_renderer.rb
      create  config/initializers/assets.rb
      create  config/initializers/backtrace_silencers.rb
      create  config/initializers/cookies_serializer.rb
      create  config/initializers/cors.rb
      create  config/initializers/filter_parameter_logging.rb
      create  config/initializers/inflections.rb
      create  config/initializers/mime_types.rb
      create  config/initializers/new_framework_defaults_5_1.rb
      create  config/initializers/wrap_parameters.rb
      create  config/locales
      create  config/locales/en.yml
      create  config/boot.rb
      create  config/database.yml
      create  db
      create  db/seeds.rb
      create  lib
      create  lib/tasks
      create  lib/tasks/.keep
      create  lib/assets
      create  lib/assets/.keep
      create  log
      create  log/.keep
      create  public
      create  public/404.html
      create  public/422.html
      create  public/500.html
      create  public/apple-touch-icon-precomposed.png
      create  public/apple-touch-icon.png
      create  public/favicon.ico
      create  public/robots.txt
      create  test/fixtures
      create  test/fixtures/.keep
      create  test/fixtures/files
      create  test/fixtures/files/.keep
      create  test/controllers
      create  test/controllers/.keep
      create  test/mailers
      create  test/mailers/.keep
      create  test/models
      create  test/models/.keep
      create  test/helpers
      create  test/helpers/.keep
      create  test/integration
      create  test/integration/.keep
      create  test/test_helper.rb
      create  test/system
      create  test/system/.keep
      create  test/application_system_test_case.rb
      create  tmp
      create  tmp/.keep
      create  tmp/cache
      create  tmp/cache/assets
      create  vendor
      create  vendor/.keep
      create  package.json
      remove  config/initializers/cors.rb
      remove  config/initializers/new_framework_defaults_5_1.rb
         run  bundle install
Do not run Bundler as root. Bundler can ask for sudo if it is needed, and installing your bundle as root will break this application for all non-root users on this machine.
The dependency tzinfo-data (>= 0) will be unused by any of the platforms Bundler is installing for. Bundler is installing for ruby but the dependency is only for x86-mingw32, x86-mswin32, x64-mingw32, java. To add those platforms to the bundle, run `bundle lock --add-platform x86-mingw32 x86-mswin32 x64-mingw32 java`                                                                              .
Fetching gem metadata from https://rubygems.org/.........
Fetching version metadata from https://rubygems.org/..
Fetching dependency metadata from https://rubygems.org/.
Resolving dependencies...
Fetching rake 12.0.0
Installing rake 12.0.0
Using concurrent-ruby 1.0.5
Using i18n 0.8.4
Fetching minitest 5.10.2
Installing minitest 5.10.2
Using thread_safe 0.3.6
Using builder 3.2.3
Using erubi 1.6.1
Using mini_portile2 2.2.0
Using rack 2.0.3
Using nio4r 2.1.0
Using websocket-extensions 0.1.2
Using mime-types-data 3.2016.0521
Using arel 8.0.0
Using bundler 1.15.1
Using method_source 0.8.2
Using thor 0.19.4
Fetching sqlite3 1.3.13
Installing sqlite3 1.3.13 with native extensions
Fetching puma 3.9.1
Installing puma 3.9.1 with native extensions
Fetching sass 3.4.24
Installing sass 3.4.24
Fetching tilt 2.0.7
Installing tilt 2.0.7
Fetching execjs 2.7.0
Installing execjs 2.7.0
Fetching coffee-script-source 1.12.2
Installing coffee-script-source 1.12.2
Fetching turbolinks-source 5.0.3
Installing turbolinks-source 5.0.3
Fetching multi_json 1.12.1
Installing multi_json 1.12.1
Fetching byebug 9.0.6
Installing byebug 9.0.6 with native extensions
Fetching public_suffix 2.0.5
Installing public_suffix 2.0.5
Fetching ffi 1.9.18
Installing ffi 1.9.18 with native extensions
Fetching rubyzip 1.2.1
Installing rubyzip 1.2.1
Fetching bindex 0.5.0
Installing bindex 0.5.0 with native extensions
Fetching rb-fsevent 0.10.2
Installing rb-fsevent 0.10.2
Fetching ruby_dep 1.3.1
Installing ruby_dep 1.3.1
Using tzinfo 1.2.3
Using nokogiri 1.8.0
Using rack-test 0.6.3
Using sprockets 3.7.1
Using websocket-driver 0.6.5
Using mime-types 3.1
Fetching uglifier 3.2.0
Installing uglifier 3.2.0
Fetching coffee-script 2.4.1
Installing coffee-script 2.4.1
Fetching turbolinks 5.0.1
Installing turbolinks 5.0.1
Fetching addressable 2.5.1
Installing addressable 2.5.1
Fetching childprocess 0.7.1
Installing childprocess 0.7.1
Fetching rb-inotify 0.9.10
Installing rb-inotify 0.9.10
Using activesupport 5.1.2
Using loofah 2.0.3
Fetching xpath 2.1.0
Installing xpath 2.1.0
Using mail 2.6.6
Fetching selenium-webdriver 3.4.3
Installing selenium-webdriver 3.4.3
Fetching listen 3.1.5
Installing listen 3.1.5
Using rails-dom-testing 2.0.3
Using globalid 0.4.0
Using activemodel 5.1.2
Fetching jbuilder 2.7.0
Installing jbuilder 2.7.0
Fetching spring 2.0.2
Installing spring 2.0.2
Using rails-html-sanitizer 1.0.3
Fetching capybara 2.14.4
Installing capybara 2.14.4
Using activejob 5.1.2
Using activerecord 5.1.2
Fetching spring-watcher-listen 2.0.1
Installing spring-watcher-listen 2.0.1
Using actionview 5.1.2
Using actionpack 5.1.2
Using actioncable 5.1.2
Using actionmailer 5.1.2
Using railties 5.1.2
Using sprockets-rails 3.2.0
Fetching coffee-rails 4.2.2
Installing coffee-rails 4.2.2
Fetching web-console 3.5.1
Installing web-console 3.5.1
Using rails 5.1.2
Fetching sass-rails 5.0.6
Installing sass-rails 5.0.6
Bundle complete! 16 Gemfile dependencies, 69 gems now installed.
Use `bundle info [gemname]` to see where a bundled gem is installed.
         run  bundle exec spring binstub --all
RubyDep: WARNING: Your Ruby has security vulnerabilities! (To disable warnings, set RUBY_DEP_GEM_SILENCE_WARNINGS=1)
RubyDep: WARNING: Your Ruby is: 2.2.3 (insecure). Recommendation: install 2.2.5 or 2.3.1. (Or, at least to 2.2.4 or 2.3.0)
* bin/rake: spring inserted
* bin/rails: spring inserted
 
(envruby) root@localhost:~# cd blog
(envruby) root@localhost:~/blog# ls -al
합계 84
drwxr-xr-13 root root 4096  7월  7 19:23 .
drwx--x--60 root root 4096  7월  7 19:23 ..
drwxr-xr-x  7 root root 4096  7월  7 19:22 .git
-rw-r--r--  1 root root  536  7월  7 19:22 .gitignore
-rw-r--r--  1 root root 1974  7월  7 19:22 Gemfile
-rw-r--r--  1 root root 4650  7월  7 19:23 Gemfile.lock
-rw-r--r--  1 root root  374  7월  7 19:22 README.md
-rw-r--r--  1 root root  227  7월  7 19:22 Rakefile
drwxr-xr-10 root root 4096  7월  7 19:22 app
drwxr-xr-x  2 root root 4096  7월  7 19:23 bin
drwxr-xr-x  5 root root 4096  7월  7 19:22 config
-rw-r--r--  1 root root  130  7월  7 19:22 config.ru
drwxr-xr-x  2 root root 4096  7월  7 19:22 db
drwxr-xr-x  4 root root 4096  7월  7 19:22 lib
drwxr-xr-x  2 root root 4096  7월  7 19:22 log
-rw-r--r--  1 root root   62  7월  7 19:22 package.json
drwxr-xr-x  2 root root 4096  7월  7 19:22 public
drwxr-xr-x  9 root root 4096  7월  7 19:22 test
drwxr-xr-x  3 root root 4096  7월  7 19:22 tmp
drwxr-xr-x  2 root root 4096  7월  7 19:22 vendor
cs


2) 다음 명령을 통해 Rails application builder 의 다양한 옵션에 대해 알 수 있다.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
(envruby) root@localhost:~/blog# rails new -h
Usage:
  rails new APP_PATH [options]
 
Options:
  -r, [--ruby=PATH]                                      # Path to the Ruby binary of your choice
                                                         # Default: /root/anaconda/envs/envruby/bin/ruby
  -m, [--template=TEMPLATE]                              # Path to some application template (can be a filesystem path or URL)
  -d, [--database=DATABASE]                              # Preconfigure for selected database (options: mysql/postgresql/sqlite3/oracle/frontbase/ibm_db/sqlserver/jdbcmysql/jdbcsqlite3/jdbcpostgresql/jdbc)
                                                         # Default: sqlite3
      [--skip-yarn], [--no-skip-yarn]                    # Don't use Yarn for managing JavaScript dependencies
      [--skip-gemfile], [--no-skip-gemfile]              # Don't create a Gemfile
  -G, [--skip-git], [--no-skip-git]                      # Skip .gitignore file
      [--skip-keeps], [--no-skip-keeps]                  # Skip source control .keep files
  -M, [--skip-action-mailer], [--no-skip-action-mailer]  # Skip Action Mailer files
  -O, [--skip-active-record], [--no-skip-active-record]  # Skip Active Record files
  -P, [--skip-puma], [--no-skip-puma]                    # Skip Puma related files
  -C, [--skip-action-cable], [--no-skip-action-cable]    # Skip Action Cable files
  -S, [--skip-sprockets], [--no-skip-sprockets]          # Skip Sprockets files
      [--skip-spring], [--no-skip-spring]                # Don't install Spring application preloader
      [--skip-listen], [--no-skip-listen]                # Don't generate configuration that depends on the listen gem
      [--skip-coffee], [--no-skip-coffee]                # Don't use CoffeeScript
  -J, [--skip-javascript], [--no-skip-javascript]        # Skip JavaScript files
      [--skip-turbolinks], [--no-skip-turbolinks]        # Skip turbolinks gem
  -T, [--skip-test], [--no-skip-test]                    # Skip test files
      [--skip-system-test], [--no-skip-system-test]      # Skip system test 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
      [--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
      [--api], [--no-api]                                # Preconfigure smaller stack for API only apps
  -B, [--skip-bundle], [--no-skip-bundle]                # Don't run bundle install
      [--webpack=WEBPACK]                                # Preconfigure for app-like JavaScript with Webpack (options: react/vue/angular)
 
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.
(envruby) root@localhost:~/blog#
cs


3) blog 디렉토리 구성요소 및 기능

앞에서 생성된 blog 디렉토리는 레일즈 어플리케이션의 토대를 이루는 자동 생성 파일과 폴더를 포함합니다. 아래는 각각의 폴더와 파일의 기능입니다.

File/Folder Purpose
app/ Contains the controllers, models, views, helpers, mailers, channels, jobs and assets for your application. You'll focus on this folder for the remainder of this guide.
bin/ Contains the rails script that starts your app and can contain other scripts you use to setup, update, deploy or run your application.
config/ Configure your application's routes, database, and more. This is covered in more detail in Configuring Rails Applications.
config.ru Rack configuration for Rack based servers used to start the application.
db/ Contains your current database schema, as well as the database migrations.
Gemfile
Gemfile.lock
These files allow you to specify what gem dependencies are needed for your Rails application. These files are used by the Bundler gem. For more information about Bundler, see the Bundler website.
lib/ Extended modules for your application.
log/ Application log files.
public/ The only folder seen by the world as-is. Contains static files and compiled assets.
Rakefile This file locates and loads tasks that can be run from the command line. The task definitions are defined throughout the components of Rails. Rather than changing Rakefile, you should add your own tasks by adding files to the lib/tasks directory of your application.
README.md
test/ Unit tests, fixtures, and other test apparatus. These are covered in Testing Rails Applications.
tmp/ Temporary files (like cache and pid files).
vendor/ A place for all third-party code. In a typical Rails application this includes vendored gems.
.gitignore This file tells git which files (or patterns) it should ignore. See Github - Ignoring files for more info about ignoring files.


4. Hello, Rails!

다음과 같이 웹서버를 구동해보자.

1
2
3
4
5
6
7
8
9
10
11
12
(envruby) root@localhost:~/blog# bin/rails server
RubyDep: WARNING: Your Ruby has security vulnerabilities! (To disable warnings, set RUBY_DEP_GEM_SILENCE_WARNINGS=1)
RubyDep: WARNING: Your Ruby is: 2.2.3 (insecure). Recommendation: install 2.2.5 or 2.3.1. (Or, at least to 2.2.4 or 2.3.0)
=> Booting Puma
=> Rails 5.1.2 application starting in development on http://localhost:3000
=> Run `rails server -h` for more startup options
Puma starting in single mode...
* Version 3.9.1 (ruby 2.2.3-p173), codename: Private Caller
* Min threads: 5, max threads: 5
* Environment: development
* Listening on tcp://0.0.0.0:3000
Use Ctrl-C to stop
cs


2) Say "Hello", Rails
최소한의 컨트롤러와 뷰를 통해 'Hello'를 출력해보자. 컨트롤러의 목적은 특정한 요청을 수신하는 것이다. 어떤 컨트롤러가 어떤 요청을 수신할지 라우팅을 통해 결정한다. 가끔 컨트롤러로 가는 하나 이상의 루트가 있을 수 있다. 정보를 수집하여 뷰로 전달해준다.

뷰는 단지 정보를 보여줄 뿐 핵심기능은 컨트롤러에 있다. 기본적으로 뷰 템플릿은 루비에 내장된 eRuby 라는 언어로 작성된다.

다음과 같이 컨트롤러 제너레이터를 실행하여 "index"라는 액션을 가진 "Welcome"라는 컨트롤러를 만든다.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
(envruby) root@localhost:~/blog# bin/rails generate controller Welcome index
RubyDep: WARNING: Your Ruby has security vulnerabilities! (To disable warnings, set RUBY_DEP_GEM_SILENCE_WARNINGS=1)
RubyDep: WARNING: Your Ruby is: 2.2.3 (insecure). Recommendation: install 2.2.5 or 2.3.1. (Or, at least to 2.2.4 or 2.3.0)
RubyDep: WARNING: Your Ruby has security vulnerabilities! (To disable warnings, set RUBY_DEP_GEM_SILENCE_WARNINGS=1)
RubyDep: WARNING: Your Ruby is: 2.2.3 (insecure). Recommendation: install 2.2.5 or 2.3.1. (Or, at least to 2.2.4 or 2.3.0)
Running via Spring preloader in process 12227
      create  app/controllers/welcome_controller.rb
       route  get 'welcome/index'
      invoke  erb
      create    app/views/welcome
      create    app/views/welcome/index.html.erb
      invoke  test_unit
      create    test/controllers/welcome_controller_test.rb
      invoke  helper
      create    app/helpers/welcome_helper.rb
      invoke    test_unit
      invoke  assets
      invoke    coffee
      create      app/assets/javascripts/welcome.coffee
      invoke    scss
      create      app/assets/stylesheets/welcome.scss
cs


여기서 중요한 2개의 파일은 app/controllers/welcome_controller.rb 에 위치한 컨트롤러와 app/views/welcome/index.html.erb 에 위치한 뷰 파일이다.

컨트롤러 : app/controllers/welcome_controller.rb


뷰 : app/views/welcome/index.html.erb.


index.html.erb 파일을 열어 다음과 같이 수정한다.

1
<h1>Hello, Rails!</h1>
cs


3) 어플리케이션 홈페이지 설정

다음으로 실제 홈페이지 위치를 Rails 에게 알려줘야 한다.

config/routes.rb 을 열어보면 다음과 같다.

1
2
3
4
5
Rails.application.routes.draw do
  get 'welcome/index'
 
  # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
end
cs

위는 들어오는 요청을 어떻게 처리해야하는지를 담고 있는 라우팅 파일이다. 아래와 같이 수정해보자.


1
2
3
4
5
Rails.application.routes.draw do
  get 'welcome/index'
 
  root 'welcome#index'
end
cs


방금 추가한 root 'welcome#index' 가 의미하는 것은 레일스로 하여금 어플리케이션의 root 에 대한 요청을 welcome 컨트롤러의 index 액션으로 맵핑하고 'welcome/index'는 http://localhost:3000/welcome/index 를 welcome 컨트롤러의 인덱스 액션으로 맵핑한다. 이는 앞선 4.2)에서 컨트롤러를 생성(bin/rails generate controller Welcome index)하는 과정을 통해 만들어졌다.

이제 다시 웹서버를 실행시켜보자. 브라우저에서 http://localhost:3000 라고 치면 "Hello, Rails!" 라는 메시지를 만날 수 있다.



5 Getting Up and Running


Blog 어플리케이션에 새로운 리소스를 생성해보자. 리소스라는 것은 유사한 객체의 집합을 의미하는 것으로, 에를 들어 기사, 사람, 동물들이 여기에 해당한다. 그리고 해당 리소스의 아이템에 대해 소위 CRUD 라는 생성, 조회, 업데이트, 삭제가 가능하다. 다음과 같이 article 리소스를 config/routes.rb 에 추가할 수 있다.

config/routes.rb

1
2
3
4
5
6
7
Rails.application.routes.draw do
  get 'welcome/index'
  
  resources :articles
 
  root 'welcome#index'
end
cs

bin/rails routes 를 실행하면 다음과 같다.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
(envruby) root@localhost:~/blog# bin/rails routes
RubyDep: WARNING: Your Ruby has security vulnerabilities! (To disable warnings, set RUBY_DEP_GEM_SILENCE_WARNINGS=1)
RubyDep: WARNING: Your Ruby is: 2.2.3 (insecure). Recommendation: install 2.2.5 or 2.3.1. (Or, at least to 2.2.4 or 2.3.0)
       Prefix Verb   URI Pattern                  Controller#Action
welcome_index GET    /welcome/index(.:format)     welcome#index
     articles GET    /articles(.:format)          articles#index
              POST   /articles(.:format)          articles#create
  new_article GET    /articles/new(.:format)      articles#new
 edit_article GET    /articles/:id/edit(.:format) articles#edit
      article GET    /articles/:id(.:format)      articles#show
              PATCH  /articles/:id(.:format)      articles#update
              PUT    /articles/:id(.:format)      articles#update
              DELETE /articles/:id(.:format)      articles#destroy
         root GET    /                            welcome#index
cs


728x90