2012年9月アーカイブ

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

[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

今日から本格的にRailsのお勉強を始めることにした。
DSCN0157s.jpg

とりあえず、RubyとRailsのインストールに関してはhistoryをコピペしておく。
 1001  yum install libyaml-devel
 1002  yum -y install git
 1003  y
 1004  yum -y install rpm-build
 1005  cd /usr/local/src/
 1006  ll
 1007  git clone http://checkinstall.izto.org/checkinstall.git/
 1008  ll
 1009  ls
 1010  ll checkinstall/
 1011  ls -la checkinstall/
 1012  yum -y install gcc-c++
 1013  yum -y install zlib-devel
 1014  yum -y install httpd-devel
 1015  ll /etc/init.d/
 1016  rpm -qa|grep httpd
 1017  ll /etc/httpd/
 1018  ll /etc/httpd/conf
 1019  apachectl -k stop
 1020  ll /usr/local/apache2/
 1021  cd /usr/local/apache2/conf/
 1022  vi httpd.conf
 1023  vi /etc/hosts
 1024  apachectl -k stop
 1025  which apachectl
 1026  mv /usr/sbin/apachectl /usr/sbin/apachectl2
 1027  apachectl -k stop
 1028  /usr/local/apache2/bin/apachectl -k stop
 1029  /usr/local/apache2/bin/apachectl -k start
 1030  locate httpd-devel
 1031  yum -y install openssl-devel
 1032  yum -y install curl-devel
 1033  yum -y install ncurses-devel
 1034  yum -y install gdbm-devel
 1035  yum -y install readline-devel
 1036  yum -y install sqlite-devel
 1038  cd /usr/local/src/
 1039  wget http://ftp.riken.jp/Linux/fedora/epel/RPM-GPG-KEY-EPEL-6
 1040  rpm --import RPM-GPG-KEY-EPEL-6
 1041  vi /etc/yum.repos.d/epel.repo
 1042  yum --enablerepo=epel install libyaml-devel
 1043  pwd
 1044  wget http://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p194.tar.gz
 1045  tar xzvf ruby-1.9.3-p194.tar.gz
 1046  cd ruby-1.9.3-p194
 1047  ./configure
 1048  make
 1049  cd ../checkinstall/
 1050  make
 1051  make install
 1052  checkinstall
 1053  mkdir /root/rpmbuild/SOURCES
 1054  mkdir -p /root/rpmbuild/SOURCES
 1055  checkinstall
 1056  ll /root/rpmbuild/
 1057  ll /root/rpmbuild/RPMS/
 1058  ll /root/rpmbuild/RPMS/i386/
 1059  rpm -i /root/rpmbuild/RPMS/i386/checkinstall-20120916-1.i386.rpm
 1060  which checkinstall
 1061  cd ../ruby-1.9.3-p194
 1062  checkinstall --fstrans=no
 1063  ll /root/rpmbuild/RPMS/
 1064  ll /root/rpmbuild/RPMS/i386/
 1065  rpm -i /root/rpmbuild/RPMS/i386/ruby-1.9.3-p194-1.i386.rpm
 1066  which ruby
 1067  ruby -v
 1068  history
 1071  gem install rails

このアーカイブについて

このページには、2012年9月に書かれたブログ記事が新しい順に公開されています。

次のアーカイブは2012年10月です。

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