デモ作成の最近のブログ記事

コントローラーとアクションを作成するのは簡単です。

[taka@centos6 demo]$ rails generate controller Say hello goodbye
      create  app/controllers/say_controller.rb
       route  get "say/goodbye"
       route  get "say/hello"
      invoke  erb
      create    app/views/say
      create    app/views/say/hello.html.erb
      create    app/views/say/goodbye.html.erb
      invoke  test_unit
      create    test/functional/say_controller_test.rb
      invoke  helper
      create    app/helpers/say_helper.rb
      invoke    test_unit
      create      test/unit/helpers/say_helper_test.rb
      invoke  assets
      invoke    coffee
      create      app/assets/javascripts/say.js.coffee
      invoke    scss
      create      app/assets/stylesheets/say.css.scss

最小限の定義だけです。
[taka@centos6 demo]$ less app/controllers/say_controller.rb
class SayController < ApplicationController
  def hello
  end

  def goodbye
  end
end

あとは、http://sabakan.org:3000/say/hello のようにアクセスすればいいです。

rake about のチェックが問題なかったので、demoアプリを起動してみる。

[taka@centos6 demo]$ rails server
=> Booting WEBrick
=> Rails 3.2.8 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
[2012-09-30 12:26:48] INFO  WEBrick 1.3.1
[2012-09-30 12:26:48] INFO  ruby 1.9.3 (2012-04-20) [i686-linux]
[2012-09-30 12:26:48] INFO  WEBrick::HTTPServer#start: pid=32668 port=3000


Started GET "/assets/rails.png" for 192.168.1.14 at 2012-09-30 12:27:10 +0900
Connecting to database specified by database.yml
Served asset /rails.png - 200 OK (7ms)

おおお!
ちゃんと起動してますね!!
rails_demo.jpg

rails newでアプリケーションの雛形を作成した後は、
まず、インストール状況を確認するコマンドを実行する必要があるらしい。

[taka@centos6 demo]$ rake about
rake aborted!
Could not find a JavaScript runtime. See https://github.com/sstephenson/execjs for a list of available runtimes.

(See full trace by running task with --trace)

またエラーが出て怒られた・・・。
ググって調べてみると、GemFileに

gem 'execjs'
gem 'therubyracer'

を追加してbundle installを実行すればいいらしい。

もう一回
>rake about
[taka@centos6 demo]$ rake about
About your application's environment
Ruby version              1.9.3 (i686-linux)
RubyGems version          1.8.23
Rack version              1.4
Rails version             3.2.8
JavaScript Runtime        therubyracer (V8)
Active Record version     3.2.8
Action Pack version       3.2.8
Active Resource version   3.2.8
Action Mailer version     3.2.8
Active Support version    3.2.8
Middleware                ActionDispatch::Static, Rack::Lock, #<ActiveSupport::Cache::Strategy::LocalCache::Middleware:0x9b620fc>, Rack::Runtime, Rack::MethodOverride, ActionDispatch::RequestId, Rails::Rack::Logger, ActionDispatch::ShowExceptions, ActionDispatch::DebugExceptions, ActionDispatch::RemoteIp, ActionDispatch::Reloader, ActionDispatch::Callbacks, ActiveRecord::ConnectionAdapters::ConnectionManagement, ActiveRecord::QueryCache, ActionDispatch::Cookies, ActionDispatch::Session::CookieStore, ActionDispatch::Flash, ActionDispatch::ParamsParser, ActionDispatch::Head, Rack::ConditionalGet, Rack::ETag, ActionDispatch::BestStandardsSupport
Application root          /home/taka/demo
Environment               development
Database adapter          sqlite3
Database schema version   0

今度は上手くいったようだ。

> rails new demo
と入力したらパスワードを求められたので、現在のアカウントのパスワードを入力した。
taka is not in the sudoers file.  This incident will be reported.

なんかエラーメッセージが出て怒られたので、sudoersにrails newを実行するユーザを書くことにした。

> vi sudo
%taka ALL=(ALL) ALL //taka に全てのroot 権限を与える

もう一回
> rails new demo
Enter your password to install the bundled RubyGems to your system:
Fetching gem metadata from https://rubygems.org/.........
Using rake (0.9.2.2)
Using i18n (0.6.1)
Using multi_json (1.3.6)
Using activesupport (3.2.8)
Using builder (3.0.3)
Using activemodel (3.2.8)
Using erubis (2.7.0)
Using journey (1.0.4)
Using rack (1.4.1)
Using rack-cache (1.2)
Installing rack-test (0.6.2)
Using hike (1.2.1)
Using tilt (1.3.3)
Using sprockets (2.1.3)
Using actionpack (3.2.8)
Using mime-types (1.19)
Using polyglot (0.3.3)
Using treetop (1.4.10)
Using mail (2.4.4)
Using actionmailer (3.2.8)
Using arel (3.0.2)
Using tzinfo (0.3.33)
Using activerecord (3.2.8)
Using activeresource (3.2.8)
Using bundler (1.2.0)
Installing coffee-script-source (1.3.3)
Installing execjs (1.4.0)
Installing coffee-script (2.2.0)
Using rack-ssl (1.3.2)
Using json (1.7.5)
Using rdoc (3.12)
Using thor (0.16.0)
Using railties (3.2.8)
Installing coffee-rails (3.2.2)
Installing jquery-rails (2.1.3)
Using rails (3.2.8)
Installing sass (3.2.1)
Installing sass-rails (3.2.5)
Using sqlite3 (1.3.6)
Installing uglifier (1.3.0)
Your bundle is complete! Use `bundle show [gemname]` to see where a bundled gem is installed.

今度は上手いった。
ちゃんと、アプリケーションの雛形が作成されてますね。
> ll demo
合計 72
-rw-rw-r-- 1 taka taka  765  9月 30 12:00 2012 Gemfile
-rw-rw-r-- 1 taka taka 2472  9月 30 12:01 2012 Gemfile.lock
-rw-rw-r-- 1 taka taka 9208  9月 30 12:00 2012 README.rdoc
-rw-rw-r-- 1 taka taka  269  9月 30 12:00 2012 Rakefile
drwxrwxr-x 8 taka taka 4096  9月 30 12:00 2012 app
drwxrwxr-x 5 taka taka 4096  9月 30 12:00 2012 config
-rw-rw-r-- 1 taka taka  154  9月 30 12:00 2012 config.ru
drwxrwxr-x 2 taka taka 4096  9月 30 12:00 2012 db
drwxrwxr-x 2 taka taka 4096  9月 30 12:00 2012 doc
drwxrwxr-x 4 taka taka 4096  9月 30 12:00 2012 lib
drwxrwxr-x 2 taka taka 4096  9月 30 12:00 2012 log
drwxrwxr-x 2 taka taka 4096  9月 30 12:00 2012 public
drwxr-xr-x 2 taka taka 4096  9月 30 12:00 2012 script
drwxrwxr-x 7 taka taka 4096  9月 30 12:00 2012 test
drwxrwxr-x 3 taka taka 4096  9月 30 12:00 2012 tmp
drwxrwxr-x 4 taka taka 4096  9月 30 12:00 2012 vendor

このアーカイブについて

このページには、過去に書かれたブログ記事のうちデモ作成カテゴリに属しているものが含まれています。

前のカテゴリはMySQLです。

最近のコンテンツはインデックスページで見られます。過去に書かれたものはアーカイブのページで見られます。