ラベル Rails の投稿を表示しています。 すべての投稿を表示
ラベル Rails の投稿を表示しています。 すべての投稿を表示

2014年3月31日月曜日

[Rails4]本番環境でSQLのログを出力する方法

このエントリーをはてなブックマークに追加 Clip to Evernote
調査のためにSQLログが欲しかったので出力する方法をググって探してみた

config/configatron/production.rbに以下の行を追加すると、本番環境でSQLのログが出力されるようになる。
もちろん、常に出しっぱなしだとパフォーマンスに影響が出るので調査の時だけね。。

2014年2月21日金曜日

[Mac][Ruby]bundleでEACCES: Permission deniedのエラーが出た

このエントリーをはてなブックマークに追加 Clip to Evernote
放置してたけど、いい加減良くないと思ったのでググってみた。

Errno::EACCES: Permission denied - /Library/Ruby/Gems/2.0.0/build_info/carrierwave-0.9.0.info
An error occurred while installing carrierwave (0.9.0), and Bundler cannot
continue.
Make sure that `gem install carrierwave -v '0.9.0'` succeeds before bundling.


出てますー出てますー
そこで!

ググったところ、Console Tools入れろってさ。
入れたはずなんだけどなぁ。。
Mavericksに上げたからなくなったのかしら。。

そしてググると!
なんとコマンドでインストールする方法が出てきた!

これは知らなかったぞ

xcode-select --install
使用許諾のウインドウが出て許可するだけで終わり。

ちなみに、コンソールツール入れてbundleしたら、今度は

bundle install --path vendor/bundle
しなさいと言われたので、言われた通りにやったらエラーも出なくなりました。
めでたしめでたし

2013年1月9日水曜日

[Rails][Windows]eclipseにRedRailsを入れる

このエントリーをはてなブックマークに追加 Clip to Evernote
Windowsで開発するときに慣れてるeclipseにプラグインを入れて開発したかったので、
RedRailsを入れる方法をまとめます。
※2013/01/09時点の情報です

以下のサイトを参考にさせていただきました。
Eclipse プラグイン版 RadRails のインストール

■ローカル環境

Windows7
eclipse Juno Service Release 1

■Aptana RedRailsの対応バージョン


System Requirements
Eclipse 3.6 or better
と書いてあるので、3.6以上のバージョンがいいようです。


1.Aptana RadRailsのページを開く

http://www.aptana.com/products/radrails/

2.Downloadsをクリック


3.Eclipse Plug-in Versionを選択する


4.下にあるnameとemailに入力して、DOWNLOADをクリック


5.eclipseで『Install New Software』で登録するURLが表示されるのでコピー


6.eclipseを起動して、[Help]->[Install New Software]をクリック


7.Work with に先ほどコピーしたURLを貼り付ける


8.[Add...]ををクリックして、nameを入力。入力したらOKをクリック

nameはわかるものであればなんでもいいです。
ここでは、『RedRails』と入力しました。

7.ロードが終わったら、『Aptana RedRails』にチェックを入れて、Nextをクリック


8.プレビュー画面が表示されるのでそのままNextをクリック



9.ライセンスの確認画面が出るので、acceptを選択してFinishをクリック

10.インストールが終わったら、eclipseを再起動するかどうか聞かれるので、Yesをクリックして再起動する。

11.aptana のStart Pageが表示されればOK

次はプロジェクトのインポートです。


2012年9月26日水曜日

[Rails]ルーティングについて-初級編-

このエントリーをはてなブックマークに追加 Clip to Evernote
今回はルーティングの話。初級編ですー

Railsでは、URLから特定のコントローラとアクションを選ぶことを『ルーティング』と呼びます。
ルーティングの設定は、 /config/routes.rb で指定します。
こんな感じですね↓

アプリケーション名::Application.routes.draw do   ルーティングを記述する
end
実際に、アプリケーションに新しいactionを追加して、ルーティングの設定をしてみます。

routes.rb に以下を追加

この設定により、『/about』というパスでアクセスが来た時に、TopControllerのaboutアクションを呼び出すようになります。


TopControllerにaboutアクションを追加

aboutアクションは特に何もしません。

viewを作成

about.html.erbを作成します。ついでに、ちょっとインスタンス変数も使ってます。

サーバを起動

サーバを起動します。
rails server
ブラウザから、『http://localhost:3000/about』にアクセスしてみましょう。
こんな表示になればOKです。


2012年9月25日火曜日

[Rails][Mac]アプリケーションを作成する

このエントリーをはてなブックマークに追加 Clip to Evernote
今回はローカルで、アプリケーションを作成する手順のまとめです。
※rubyのインストール等は終わってる前提です。インストール手順などの詳細はこちらを参考にしてください。

まずはRailsのインストール

適当なディレクトリを作成します。
$ mkdir rails
で、作成したディレクトリに移動します。
$ cd rails
そこにrailsをインストールします。
$ gem install rails
以下のようにいろいろ必要なものをインストールしてくれます。

gem install rails
Fetching: i18n-0.6.1.gem (100%)
Fetching: activesupport-3.2.8.gem (100%)
Fetching: builder-3.0.3.gem (100%)
Fetching: activemodel-3.2.8.gem (100%)
Fetching: rack-1.4.1.gem (100%)
Fetching: rack-cache-1.2.gem (100%)
Fetching: rack-test-0.6.1.gem (100%)
Fetching: journey-1.0.4.gem (100%)
Fetching: hike-1.2.1.gem (100%)
Fetching: tilt-1.3.3.gem (100%)
Fetching: sprockets-2.1.3.gem (100%)
Fetching: erubis-2.7.0.gem (100%)
Fetching: actionpack-3.2.8.gem (100%)
Fetching: arel-3.0.2.gem (100%)
Fetching: tzinfo-0.3.33.gem (100%)
Fetching: activerecord-3.2.8.gem (100%)
Fetching: activeresource-3.2.8.gem (100%)
Fetching: polyglot-0.3.3.gem (100%)
Fetching: treetop-1.4.10.gem (100%)
Fetching: mail-2.4.4.gem (100%)
Fetching: actionmailer-3.2.8.gem (100%)
Fetching: rack-ssl-1.3.2.gem (100%)
Fetching: thor-0.16.0.gem (100%)
Fetching: json-1.7.5.gem (100%)
Building native extensions.  This could take a while...
Fetching: rdoc-3.12.gem (100%)
Depending on your version of ruby, you may need to install ruby rdoc/ri data:
<= 1.8.6 : unsupported
 = 1.8.7 : gem install rdoc-data; rdoc-data --install
 = 1.9.1 : gem install rdoc-data; rdoc-data --install
>= 1.9.2 : nothing to do! Yay!
Fetching: railties-3.2.8.gem (100%)
Fetching: rails-3.2.8.gem (100%)
Successfully installed i18n-0.6.1
Successfully installed activesupport-3.2.8
Successfully installed builder-3.0.3
Successfully installed activemodel-3.2.8
Successfully installed rack-1.4.1
Successfully installed rack-cache-1.2
Successfully installed rack-test-0.6.1
Successfully installed journey-1.0.4
Successfully installed hike-1.2.1
Successfully installed tilt-1.3.3
Successfully installed sprockets-2.1.3
Successfully installed erubis-2.7.0
Successfully installed actionpack-3.2.8
Successfully installed arel-3.0.2
Successfully installed tzinfo-0.3.33
Successfully installed activerecord-3.2.8
Successfully installed activeresource-3.2.8
Successfully installed polyglot-0.3.3
Successfully installed treetop-1.4.10
Successfully installed mail-2.4.4
Successfully installed actionmailer-3.2.8
Successfully installed rack-ssl-1.3.2
Successfully installed thor-0.16.0
Successfully installed json-1.7.5
Successfully installed rdoc-3.12
Successfully installed railties-3.2.8
Successfully installed rails-3.2.8
27 gems installed
Installing ri documentation for i18n-0.6.1...
Installing ri documentation for activesupport-3.2.8...
Installing ri documentation for builder-3.0.3...
Installing ri documentation for activemodel-3.2.8...
Installing ri documentation for rack-1.4.1...
Installing ri documentation for rack-cache-1.2...
Installing ri documentation for rack-test-0.6.1...
Installing ri documentation for journey-1.0.4...
Installing ri documentation for hike-1.2.1...
Installing ri documentation for tilt-1.3.3...
Installing ri documentation for sprockets-2.1.3...
Installing ri documentation for erubis-2.7.0...
Installing ri documentation for actionpack-3.2.8...
Installing ri documentation for arel-3.0.2...
Installing ri documentation for tzinfo-0.3.33...
Installing ri documentation for activerecord-3.2.8...
Installing ri documentation for activeresource-3.2.8...
Installing ri documentation for polyglot-0.3.3...
Installing ri documentation for treetop-1.4.10...
Installing ri documentation for mail-2.4.4...
Installing ri documentation for actionmailer-3.2.8...
Installing ri documentation for rack-ssl-1.3.2...
Installing ri documentation for thor-0.16.0...
Installing ri documentation for json-1.7.5...
Installing ri documentation for rdoc-3.12...
Installing ri documentation for railties-3.2.8...
Installing ri documentation for rails-3.2.8...
Installing RDoc documentation for i18n-0.6.1...
Installing RDoc documentation for activesupport-3.2.8...
Installing RDoc documentation for builder-3.0.3...
Installing RDoc documentation for activemodel-3.2.8...
Installing RDoc documentation for rack-1.4.1...
Installing RDoc documentation for rack-cache-1.2...
Installing RDoc documentation for rack-test-0.6.1...
Installing RDoc documentation for journey-1.0.4...
Installing RDoc documentation for hike-1.2.1...
Installing RDoc documentation for tilt-1.3.3...
Installing RDoc documentation for sprockets-2.1.3...
Installing RDoc documentation for erubis-2.7.0...
Installing RDoc documentation for actionpack-3.2.8...
Installing RDoc documentation for arel-3.0.2...
Installing RDoc documentation for tzinfo-0.3.33...
Installing RDoc documentation for activerecord-3.2.8...
Installing RDoc documentation for activeresource-3.2.8...
Installing RDoc documentation for polyglot-0.3.3...
Installing RDoc documentation for treetop-1.4.10...
Installing RDoc documentation for mail-2.4.4...
Installing RDoc documentation for actionmailer-3.2.8...
Installing RDoc documentation for rack-ssl-1.3.2...
Installing RDoc documentation for thor-0.16.0...
Installing RDoc documentation for json-1.7.5...
Installing RDoc documentation for rdoc-3.12...
Installing RDoc documentation for railties-3.2.8...
Installing RDoc documentation for rails-3.2.8...

これでインストールは完了。
※インストールするrailsのバージョンを指定したい場合は、
gem install rails --version "~> 3.2.1" --no-rdoc --no-ri
のコマンドを叩くと良いです。

アプリケーションを作成する

アプリケーションを作成します。
$ rails new study --skip-bundle
rails newコマンドで、『study』ディレクトリを作成して、Railsアプリケーションに必要なフォルダやファイルを作ってくれます。

      create
      create  README.rdoc
      create  Rakefile
      create  config.ru
      create  .gitignore
      create  Gemfile
      create  app
      create  app/assets/images/rails.png
      create  app/assets/javascripts/application.js
      create  app/assets/stylesheets/application.css
      create  app/controllers/application_controller.rb
      create  app/helpers/application_helper.rb
      create  app/mailers
      create  app/models
      create  app/views/layouts/application.html.erb
      create  app/mailers/.gitkeep
      create  app/models/.gitkeep
      create  config
      create  config/routes.rb
      create  config/application.rb
      create  config/environment.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/backtrace_silencers.rb
      create  config/initializers/inflections.rb
      create  config/initializers/mime_types.rb
      create  config/initializers/secret_token.rb
      create  config/initializers/session_store.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  doc
      create  doc/README_FOR_APP
      create  lib
      create  lib/tasks
      create  lib/tasks/.gitkeep
      create  lib/assets
      create  lib/assets/.gitkeep
      create  log
      create  log/.gitkeep
      create  public
      create  public/404.html
      create  public/422.html
      create  public/500.html
      create  public/favicon.ico
      create  public/index.html
      create  public/robots.txt
      create  script
      create  script/rails
      create  test/fixtures
      create  test/fixtures/.gitkeep
      create  test/functional
      create  test/functional/.gitkeep
      create  test/integration
      create  test/integration/.gitkeep
      create  test/unit
      create  test/unit/.gitkeep
      create  test/performance/browsing_test.rb
      create  test/test_helper.rb
      create  tmp/cache
      create  tmp/cache/assets
      create  vendor/assets/javascripts
      create  vendor/assets/javascripts/.gitkeep
      create  vendor/assets/stylesheets
      create  vendor/assets/stylesheets/.gitkeep
      create  vendor/plugins
      create  vendor/plugins/.gitkeep
『--skip-bundle』オプションをつけているのは、『bundle install』の実行を省略するためです。オプションを付けないと、『bundle install』が自動実行されます。

次にBundlerでGemパッケージを追加します。
$ cd study
$ bundle install
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)
Using rack-test (0.6.1)
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.2)
Using rails (3.2.8)
Installing sass (3.2.1)
Installing sass-rails (3.2.5)
Installing sqlite3 (1.3.6) with native extensions
Installing uglifier (1.3.0)
Your bundle is complete! Use `bundle show [gemname]` to see where a bundled gem is installed. 
これでインストール完了。
SQLite3とかいろいろ必要なパッケージがインストールされました。

アプリケーションを起動する

先ほど作ったアプリケーションのフォルダに移動して、サーバを起動します。
Rubyに付属されているWEBrickというウェブサーバが起動されます。
$ 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-24 07:52:41] INFO  WEBrick 1.3.1
[2012-09-24 07:52:41] INFO  ruby 1.9.3 (2012-04-20) [x86_64-darwin11.4.0]
[2012-09-24 07:52:41] INFO  WEBrick::HTTPServer#start: pid=57972 port=3000

Started GET "/assets/rails.png" for 127.0.0.1 at 2012-09-24 07:52:54 +0900
Connecting to database specified by database.yml
Served asset /rails.png - 200 OK (9ms) 
これで起動しました。
ブラウザを上げて、『http://localhost:3000』にアクセスしてみましょう。
以下のような画面が出ればOK
終了する場合は、『control』+『c』で終わります。

アプリケーションの構成を見てみる

Macでアプリケーションを作成すると、こんな感じ。

いろいろとフォルダができますが、各フォルダの役割は簡単に言うとこんな感じ。
app モデル、ビュー、コントローラのコードを置く
config ルーティングやデータベースなどの設定ファイルを置く
db マイグレーションスクリプトやシードデータを置く
doc 開発者向けのドキュメントを置く
lib 自作ライブラリやrakeファイルを置く
log ログが出力される
public アプリケーションを介さずに、静的ファイルを置く
script スクリプトファイルを置く
test テストケースを書いたテストファイルを置く
tmp キャッシュなどのテンポラリファイル
vender プラグインなどは配置する

appフォルダの下にもフォルダが分かれており、それぞれに役割があります。
appの下にはファイル名規約があるので、次のサイトを参考にしましょう。
(参考:Railsドキュメント Railsの基礎知識)

コントローラとアクションの作成

ようやくコーディングっぽいところに到達(笑)
Railsの初期画面だと味気ないので、コントローラを作成します。
コンソールに戻って、『rails generate コントローラ名 アクション名』コマンドを実行します。
generateは省略もできて、『rails g 〜』とも書けるようです。
まあ、ともかくコマンド実行しましょう。
$ rails g controller top index
      create  app/controllers/top_controller.rb
       route  get "top/index"
      invoke  erb
      create    app/views/top
      create    app/views/top/index.html.erb
      invoke  test_unit
      create    test/functional/top_controller_test.rb
      invoke  helper
      create    app/helpers/top_helper.rb
      invoke    test_unit
      create      test/unit/helpers/top_helper_test.rb
      invoke  assets
      invoke    coffee
      create      app/assets/javascripts/top.js.coffee
      invoke    scss
      create      app/assets/stylesheets/top.css.scss
TopControllerとindexアクションがこれで作成されました。
実際にファイルを見てみましょうー。
app/controllers/top_controller.rb
TopControllerクラスの中に、indexメソッドができてます。
これが、トップページを表示するアクションになります。

次に、ルーティングの設定をします。
config/route.rb を開いて、以下のように書き換えます。

書き換えたら、public/index.htmlファイルを削除します。
これを消さないと、また同じ画面が表示されることに!!

最後に、ローカルサーバを起動します。
rails server 
以下のように表示されればOK!!

ビューを作成する

次に、indexアクションに対応するテンプレートを編集します。
先ほどの画面を表示していたHTMLですね。
Railsのビューのためのテンプレートは、『アクション名』+『.html』+『.erb』というファイル名になります。(HTMLの場合は)
/app/view/top/index.html.erb を開いて、以下のように修正します。

ブラウザを再読み込みすると、表示が変わってますね。

変数を表示する

ベタ書きだとつまらんので、変数を使ってみます。
/app/controller/top_controller.rb
@messageを定義して、文字を代入します。
テンプレートの方もmessageを読み込むように修正します。変数をテンプレートで読み込む場合は、<%=  %>で変数を囲むんですな。
ブラウザをリロードするとこんな感じ。
以上、アプリケーション作成入門でした!

2012年9月17日月曜日

[Mac][Heroku]MacでHeroku環境構築

このエントリーをはてなブックマークに追加 Clip to Evernote
前回のMacでRuby環境構築でRubyの環境構築までできたので、
今回はHerokuを使ってみようの会ですw

今回の参考先もmacを買って、今すぐherokuでruby1.9.3 + rails3.2しよう!ですww
ありがとうございますm(__)m

Herokuの登録は
macを買って、今すぐherokuでruby1.9.3 + rails3.2しよう!
の『herokuアカウントを作成』から読んでね。

アカウントが作成出来たら、参考先をそのまま続けてやってきましょうー。


ssh公開鍵を作成する


以下コマンドを打って、Enterを押すと出来上がり。
$ ssh-keygen -b 2048
Generating public/private rsa key pair.
Enter file in which to save the key (/Users/xxxx/.ssh/id_rsa):   ←Enter押す
Created directory '/Users/xxxx/.ssh'.
Enter passphrase (empty for no passphrase):    ←入力せずにEnter押す
Enter same passphrase again:    ←入力せずEnter押す
Your identification has been saved in /Users/xxxx/.ssh/id_rsa.
Your public key has been saved in /Users/xxxx/.ssh/id_rsa.pub.
fingerprintとか表示されるので、眺めて終了。
作った公開鍵を登録
heroku keys:add

rvm gemsetを作成する

rvm gemsetってなんじゃらホイと思ってぐぐってみました。
RVM gemset とは?によると、rubyのバージョンと使用用途によってgemの組み合わせやバージョンを管理できるようになる仕組みのようです。
開発環境によって、組み合わせが変わったりできるとか。
次のサイトで、賢い使い方がわかりやすく載ってたので、使う場合は参考にすると良いかと。(参考サイト:rvm のgemsetをおさらい(Mac でRuby))
とりあえず、heroku用のgemsetを作って見ましょうー。
以下のコマンドでOK。
rvm --create 1.9.3-p194@heroku-sample
 gemでherokuをインストールもしちゃいます。

$ gem install heroku --no-ri --no-rdoc
Fetching: excon-0.16.2.gem (100%)
Fetching: heroku-api-0.3.5.gem (100%)
Fetching: netrc-0.7.7.gem (100%)
Fetching: mime-types-1.19.gem (100%)
Fetching: rest-client-1.6.7.gem (100%)
Fetching: addressable-2.3.2.gem (100%)
Fetching: launchy-2.1.2.gem (100%)
Fetching: rubyzip-0.9.9.gem (100%)
Fetching: heroku-2.31.2.gem (100%)
 !    Heroku recommends using the Heroku Toolbelt to install the CLI.
 !    Download it from: https://toolbelt.heroku.com
Successfully installed excon-0.16.2
Successfully installed heroku-api-0.3.5
Successfully installed netrc-0.7.7
Successfully installed mime-types-1.19
Successfully installed rest-client-1.6.7
Successfully installed addressable-2.3.2
Successfully installed launchy-2.1.2
Successfully installed rubyzip-0.9.9
Successfully installed heroku-2.31.2
9 gems installed

Herokuにログインする

 herokuにログインします。
heroku login

herokuアカウントのメアドとパスワードを入力して
Authentication successful. って言われたらOK。

rails3.2.2をインストール

railsをインストールします。
2012/09/17時点で、railsの最新が3.2.8だったので、それを入れてみます。
gem install rails --version 3.2.8 --no-ri --no-rdoc
こんなかんじでインストールされて完了。

アプリを作成する

railsアプリをまず作ります。
rails new heroku-sample
mysqlとか使いたかったら、-d mysqlオプションとか入れるといいらしいです。
が、ここではデフォルトでいきますw
次に、サンプルアプリの中のディレクトリに移動します。
cd heroku-sample
gitを初期化します。
gitの使い方は、Git入門で。
次に、最低限のgemを記述します。(といってもコンソールでコマンド叩くだけ)
Gemfileの中を見てみましょう。
vi Gemfile
開発では、sqlite3で、本番だとpostgreSQLだったりするんですな。ふむふむ。

herokuにアプリを作成する

以下コマンドを実行
herokuにdeployする
どうやらうまくいったみたい。
作成したアプリを見てみましょう。
以下、コマンドを打つと、safariが起動します。
heroku open
ようやく完了!

scaffoldでアプリを作る

まずは、デフォルト表示されるindex.htmlを消します。
scaffoldでブックマークアプリを作ります。
migrationするので、一旦メンテナンスモードにします。
migrationとは、Rubyスクリプトによって、テーブルの作成やカラムの構成変更を行う機能のこと。
詳しくは、次のサイトを参考にしてください。
(参考サイト:Ruby on Rails : migration 機能でデータベーススキーマを変更する)
それでは、メンテナンスモードに切り替えます。メンテナンスモードなので、エラーが表示されなくなります。
heroku maintenance:on
herokuにdeployします。
git push heroku master
heroku側もmigrateします。
heroku run rake db:migrate
メンテナンスモードを解除します。
heroku maintenance:off
herokuを開いて確認
heroku open
こんな画面が開いたらOK
herokuでアプリ公開まで出来ました!

2012年8月1日水曜日

[Rails][Linux]Apache+Passengerを入れる

このエントリーをはてなブックマークに追加 Clip to Evernote


WEBrickを起動したけど、ブラウザ接続できなかったので、おとなしくPassengerを入れることにした。


参考にさせていただきましたm(__)m
ApacheをWEBサーバとして利用

まずは、passengerをインストール


$ gem install passenger
Fetching: fastthread-1.0.7.gem (100%)
Building native extensions.  This could take a while...
Fetching: daemon_controller-1.0.0.gem (100%)
Fetching: passenger-3.0.15.gem (100%)
Successfully installed fastthread-1.0.7
Successfully installed daemon_controller-1.0.0
Successfully installed passenger-3.0.15
3 gems installed
Installing ri documentation for fastthread-1.0.7...
Installing ri documentation for daemon_controller-1.0.0...
Installing ri documentation for passenger-3.0.15...
Installing RDoc documentation for fastthread-1.0.7...
Installing RDoc documentation for daemon_controller-1.0.0...
Installing RDoc documentation for passenger-3.0.15...


対話式でモジュールをインストール
$ passenger-install-apache2-module
なんかいろいろ入ってないよー。でも心配しないで!
足りないやつをインストールする方法教えるから!
みたいなこと言われます。親切ですね。


私の環境で足りなかったのは以下。


Installation instructions for required software


 * To install Curl development headers with SSL support:
   Please download Curl from http://curl.haxx.se/libcurl and make sure you install it with SSL support.


 * To install Apache 2 development headers:
   Please download it from http://httpd.apache.org/


 * To install Apache Portable Runtime (APR) development headers:
   Please download it from http://httpd.apache.org/
   (APR is an integrated part of Apache.)


 * To install Apache Portable Runtime Utility (APU) development headers:
   Please download it from http://httpd.apache.org/
   (APR Utility is an integrated part of Apache.)


まずは、curlをインストール
$ sudo yum install curl-devel


次、Apache 2 development headers
$ sudo yum install httpd-devel


んで、もう一回モジュールをインストールする。
成功すると、httpd.conf とかにいろいろ書くんだよーと教えてくれるので、メモしましょう。


The Apache 2 module was successfully installed.


Please edit your Apache configuration file, and add these lines:


   LoadModule passenger_module /usr/local/ruby/lib/ruby/gems/1.9.1/gems/passenger-3.0.15/ext/apache2/mod_passenger.so
   PassengerRoot /usr/local/ruby/lib/ruby/gems/1.9.1/gems/passenger-3.0.15
   PassengerRuby /usr/local/ruby/bin/ruby


After you restart Apache, you are ready to deploy any number of Ruby on Rails
applications on Apache, without any further Ruby on Rails-specific
configuration!


Press ENTER to continue.


--------------------------------------------
Deploying a Ruby on Rails application: an example


Suppose you have a Rails application in /somewhere. Add a virtual host to your
Apache configuration file and set its DocumentRoot to /somewhere/public:


   <VirtualHost *:80>
      ServerName www.yourhost.com
      # !!! Be sure to point DocumentRoot to 'public'!
      DocumentRoot /somewhere/public
      <Directory /somewhere/public>
         # This relaxes Apache security settings.
         AllowOverride all
         # MultiViews must be turned off.
         Options -MultiViews
      </Directory>
   </VirtualHost>


And that's it! You may also want to check the Users Guide for security and
optimization tips, troubleshooting and other useful information:


  /usr/local/ruby/lib/ruby/gems/1.9.1/gems/passenger-3.0.15/doc/Users guide Apache.html


Enjoy Phusion Passenger, a product of Phusion (www.phusion.nl) :-)
https://www.phusionpassenger.com


Phusion Passenger is a trademark of Hongli Lai & Ninh Bui.




apacheのhttpd.confに、


   LoadModule passenger_module /usr/local/ruby/lib/ruby/gems/1.9.1/gems/passenger-3.0.15/ext/apache2/mod_passenger.so
   PassengerRoot /usr/local/ruby/lib/ruby/gems/1.9.1/gems/passenger-3.0.15
   PassengerRuby /usr/local/ruby/bin/ruby


   <VirtualHost *:80>
      ServerName www.yourhost.com
      # !!! Be sure to point DocumentRoot to 'public'!
      DocumentRoot /somewhere/public
      <Directory /somewhere/public>
         # This relaxes Apache security settings.
         AllowOverride all
         # MultiViews must be turned off.
         Options -MultiViews
      </Directory>
   </VirtualHost>


を書いたら、apacheを再起動


$ service httpd restart


http://ドメイン/ にアクセスし、Welcome aboard の画面が出たら成功!


ようやっとできた~

[Rails][Linux]ちょっぱやでブログサイトを作る

このエントリーをはてなブックマークに追加 Clip to Evernote

なによりも動かさないことにはわからん。
ので、Railsでよく紹介される、ちょっぱやでブログサイトを作ってみる。


がっつり参考にさせていただきました。


簡単!Rails3.2を使って10分でブログアプリを構築する方法
http://dqn.sakusakutto.jp/2012/03/rails32blog.html


まずは、プロジェクト(アプリケーション)を作成
$ rails new project(プロジェクト名)
$ cd project
$ vi GemFile


GemFileを編集して以下追加
$ gem 'execjs'
$ gem 'therubyracer'


サーバ起動
$ rails server
Could not find gem 'therubyracer (>= 0) ruby' in the gems available on this machine.
Run `bundle install` to install missing gems.


ええー


therubyracerがgemに登録されてないんだって。ましーんにないんだってさ。
懲りずに入れましょう。
$ gem install therubyracer
Fetching: libv8-3.3.10.4-x86_64-linux.gem (100%)
Fetching: therubyracer-0.10.1.gem (100%)
Building native extensions.  This could take a while...
Successfully installed libv8-3.3.10.4-x86_64-linux
Successfully installed therubyracer-0.10.1
2 gems installed
Installing ri documentation for libv8-3.3.10.4-x86_64-linux...
Installing ri documentation for therubyracer-0.10.1...
Installing RDoc documentation for libv8-3.3.10.4-x86_64-linux...
Installing RDoc documentation for therubyracer-0.10.1...


無事完了。


サーバ起動に再びトライ
rails server
=> Booting WEBrick
=> Rails 3.2.7 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
[2012-07-31 16:42:04] INFO  WEBrick 1.3.1
[2012-07-31 16:42:04] INFO  ruby 1.9.3 (2012-04-20) [x86_64-linux]
[2012-07-31 16:42:04] INFO  WEBrick::HTTPServer#start: pid=8141 port=3000


なんかよさそう。


http://localhost:3000/
にアクセスして、Welcome aboard画面が出ればOK


って出ません!!!Σ(´∀`;)


なんか別の理由っぽい気がするので


続きはまた次回。。

[Rails][Linux]Railsアプリケーションを作成する

このエントリーをはてなブックマークに追加 Clip to Evernote
環境設定が終わったら、次はアプリケーションの作成\(^o^)/


rails new プロジェクト名 で基本的なディレクトリや各種スクリプトが生成される。


$ rails new プロジェクト名
      create
      create  README.rdoc
      create  Rakefile
      create  config.ru
      create  .gitignore
      create  Gemfile
      create  app
      create  app/assets/images/rails.png
      create  app/assets/javascripts/application.js
      --(省略)--


でろでろといろいろ生成してくれます。


と思ってたら、
An error occured while installing sqlite3 (1.3.6), and Bundler cannot continue.
Make sure that `gem install sqlite3 -v '1.3.6'` succeeds before bundling.


なんてエラーが出てた。。
要は、sqlite3がないよーーと言いたいのね。
今回は特にDBにはこだわってないので、sqliteを入れることにしよう。


実行しろと言ってるコマンドを実行


$ gem install sqlite3 -v '1.3.6'


そしてまたエラー。。


Building native extensions.  This could take a while...
ERROR:  Error installing sqlite3:
        ERROR: Failed to build gem native extension.


        /usr/local/ruby/bin/ruby extconf.rb
checking for sqlite3.h... no
sqlite3.h is missing. Try 'port install sqlite3 +universal'
or 'yum install sqlite-devel' and check your shared library search path (the
location where your sqlite3 shared library is located).
*** extconf.rb failed ***


なんかyumで入れてから実行しろやってこと??


お望み通り実行
$ sudo yum install sqlite-devel
(省略)
Downloading Packages:
sqlite-devel-3.6.20-1.8.amzn1.x86_64.rpm                 |  79 kB     00:00
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing : sqlite-devel-3.6.20-1.8.amzn1.x86_64                         1/1


Installed:
  sqlite-devel.x86_64 0:3.6.20-1.8.amzn1


Complete!


はい、入りましたよー


で、もう一回。


$ gem install sqlite3 -v '1.3.6'
Building native extensions.  This could take a while...
Successfully installed sqlite3-1.3.6
1 gem installed
Installing ri documentation for sqlite3-1.3.6...
Installing RDoc documentation for sqlite3-1.3.6...


今度はうまくいったみたい。


というわけで、今度こそプロジェクト作成コマンド実行。


Your bundle is complete! Use `bundle show [gemname]` to see where a bundled gem is installed.


成功ー!!


どうやらカレントディレクトリの配下にアプリケーションが生成されるので、
/var/www/ の下など、任意の場所に作ると良いみたいです。

[Rails][Linux]Railsをインストールする

このエントリーをはてなブックマークに追加 Clip to Evernote

Linux環境にRailsをインストール

私はいつぞやか立てたAWSのサーバを使用しています。

まずは作業用ディレクトリを作成
$ mkdir ruby_install_workdir
$ cd ruby_install_workdir

Rubyの公式サイトから最新のソースコードをダウンロード
$ wget ftp://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p194.tar.gz

圧縮ファイルを展開する
$ tar zxvf ruby-1.9.3-p194.tar.gz

展開したら移動
$ cd ruby-1.9.3-p194

rubyをコンパイルしてインストール
$ ./configure --prefix=/usr/local/ruby

とここでエラー。。
$ ./configure --prefix=/usr/local/ruby
checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
checking target system type... x86_64-unknown-linux-gnu
checking for gcc... no
checking for cc... no
checking for cl.exe... no
configure: error: in `/home/---/ruby_install_workdir/ruby-1.9.3-p194':
configure: error: no acceptable C compiler found in $PATH
See `config.log' for more details

どうやらコンパイラーがないらしい。
http://news.trippyboy.com/serversmanvps/serversmanvps-configure-error-no-acceptable-c-compiler-found-in-path/

sudo yum -y install gcc
でインストール

で、気を取り直してもう一回。
$ ./configure --prefix=/usr/local/ruby
--省略--
checking for pthread.h... yes
checking for if make is GNU make... ./configure: line 17125: make: command not found
no
checking for safe null command for make... configure: error: no candidate for safe null command
まさかのmakeがインストールされていない件orz
慌てずyumでインストール
$ sudo yum install make

で、気を取り直してもう一回。
$ ./configure --prefix=/usr/local/ruby
$ make
$ sudo make install
結構時間が掛かるので、のんびりしましょう。

コマンド実行が出来るように環境変数PATHを設定しておく
$ export PATH=/usr/local/ruby/bin:$PATH

rubyのバージョンを確認
$ ruby -v
ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-linux]

最後にRailsをインストール
$ sudo gem install rails

libyamlがないYO!と言い出したので、そいつもインストール
http://maeda.farend.ne.jp/blog/2012/03/10/ruby-missing-pysh/
$ sudo rpm -Uvh http://dl.fedoraproject.org/pub/epel/5/i386/epel-release-5-4.noarch.rpm
$ sudo yum install libyaml-devel

YAMLもないって言い出した。。うう
$ wget http://pyyaml.org/download/libyaml/yaml-0.1.4.tar.gz
$ ./configure
$ make
# make install

どうやら、AmazonLinuxの素の状態だと、いろいろ足りないらしいので、他にもコケないよういれておく
http://d.hatena.ne.jp/the_yokochi/20111127/1322382198
$ sudo yum groupinstall "Development Tools"
$ sudo yum install openssl-devel readline-devel zlib-devel libyaml-devel

再度rubyをコンパイルする。
終わったらgemが使用出来るか確認
$ gem -v
1.8.23

最後にRailsをインストール
$ gem install rails

Railsのバージョンを確認
$ rails -v

長かった。。。

2012年7月30日月曜日

[Rails][Ruby]初心者のためのRuby on Railsまとめ

このエントリーをはてなブックマークに追加 Clip to Evernote
Ruby超初心者がRailsを入れて勉強ー。
随時更新予定。

参考図書


■インストール編
[Rails][Linux]Railsをインストールする
【Windows編】Railsをインストール ※準備中
【Mac編】Railsをインストール ※準備中

■いろいろ準備編
[Linux]Railsアプリケーションを作成する
[Mac]アプリケーションを作成する

■入門編
[Linux]ちょっぱやでブログサイトを作る


■サーバ編
[Rails][Linux]Apache+Passengerを入れる