기본적인 레일즈의 기능이나 작동 방식에 대해 학습했다면, 이제 배운 것에 대해 조금 더 깊게 들어가고, 그들의 구조를 머릿속에 짜보자. 그에 앞서 먼저 필요한 것이 Rails의 각종 커맨드에 대해 알아보는 것이다. 먼저 가장 기본적인 명령어에 대해 알아보자.
1. rails New 이름
잘 알다시피 처음 Rails Application을 만들 때 사용하는 커맨드이다. 이름에 자신이 원하는 Application의 이름을 넣어주면 그 이름으로 새로운 디렉토리가 생성이 되고 그 밑에 Rails Application을 운영하는데 필요한 모든 파일이 생성된다. 이 때 옵션을 지정하여 생성될 파일들의 초기 세팅을 맞추어줄 수 있는데, 그 옵션들은 다음과 같다.
Usage:
rails new APP_PATH [options]
Options:
-r, [--ruby=PATH] # Path to the Ruby binary of your choice
# Default: /home/koreport/.rbenv/versions/1.9.3-p194/bin/ruby
-b, [--builder=BUILDER] # Path to a application builder (can be a filesystem path or URL)
-m, [--template=TEMPLATE] # Path to an application template (can be a filesystem path or URL)
[--skip-gemfile] # Don't create a Gemfile
[--skip-bundle] # Don't run bundle install
-G, [--skip-git] # Skip Git ignores and keeps
-O, [--skip-active-record] # Skip Active Record files
-S, [--skip-sprockets] # Skip Sprockets files
-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] # Skip JavaScript files
[--dev] # Setup the application with Gemfile pointing to your Rails checkout
[--edge] # Setup the application with Gemfile pointing to Rails repository
-T, [--skip-test-unit] # Skip Test::Unit files
[--old-style-hash] # Force using old style hash (:foo => 'bar') on Ruby >= 1.9
Runtime options:
-f, [--force] # Overwrite files that already exist
-p, [--pretend] # Run but do not make any changes
-q, [--quiet] # Supress status output
-s, [--skip] # Skip files that already exist
Rails options:
-h, [--help] # Show this help message and quit
-v, [--version] # Show Rails version number and quit
2. rails server server_application_name
rails server 커맨드는 WEBrick이라고 불리우는 루비에 같이 탑재된 작은 웹서버를 작동시킨다. 웹브라우저로 자신이 만든 Rails Application을 보고 싶을 때 언제든지 작동시키면 된다. server 대신 s로 써도 된다. server_application_name이 주어지지 않으면 default 값으로 WEBrick이 작동되지만, 나중에 gem으로 mongrel이나 unicorn을 설치했다면 rails server mongrel 이런 식으로 다른 서버 애플리케이션을 실행할 수 있다.
-p 옵션으로 포트를 설정할 수 있고, -e 옵션으로 실행할 rails enviroment를 선택할 수 있다.
rails server -e production -p 4000 이런 식으로.
Usage: rails server [mongrel, thin, etc] [options]
-p, --port=port Runs Rails on the specified port.
Default: 3000
-b, --binding=ip Binds Rails to the specified ip.
Default: 0.0.0.0
-c, --config=file Use custom rackup configuration file
-d, --daemon Make server run as a Daemon.
-u, --debugger Enable ruby-debugging for the server.
-e, --environment=name Specifies the environment to run this server under (test/development/production).
Default: development
-P, --pid=pid Specifies the PID file.
Default: tmp/pids/server.pid
-h, --help Show this help message.
3. rails generate GENERATOR [args] [options].
rails generate 커맨드는 rails application에서 필요한 요소를 추가적으로 만들 때 실행시키는 커맨드이다. 즉 controller나 view를 만들 때 일일이 자신이 파일을 만들어 넣기 보다는, 이 커맨드를 통해 생성을 하면 정확한 위치에 정해진 이름으로 해당하는 요소의 템플릿을 만들어주기 때문에 매우 편리하다.
Usage: rails generate GENERATOR [args] [options]
General options:
-h, [--help] # Print generator's options and usage
-p, [--pretend] # Run but do not make any changes
-f, [--force] # Overwrite files that already exist
-s, [--skip] # Skip files that already exist
-q, [--quiet] # Suppress status output
Please choose a generator below.
Rails:
assets
controller
generator
helper
integration_test
mailer
migration
model
observer
performance_test
resource
scaffold
scaffold_controller
session_migration
task
Coffee:
coffee:assets
Jquery:
jquery:install
Js:
js:assets
4.