SSブログ

eclipseでRuby on Rails 10回目~HelloRailsの表示~ [Ruby on Rails]

スポンサードリンク




当記事作成時の環境:Windows10 64bit、Eclipse4.5、Ruby 2.2.3、Apatana Studio3、RadRils

前回MVCについて自分なりにざっくりまとめました。
今回はMVCを意識しつつ、実際にプログラムを作成していきます!

まずはEclipseを立ち上げます。
controllers、viewsディレクトリの中にはプロジェクト作成時の標準的なファイルのみ入っています。
modelsディレクトリには何も入っていません。

2015114_No-00.png

この状態から、Diariesコンソールに下記のコマンドを打って実行します。

rails generate controller HelloRails index

実行後はこんな感じで出力されます。

2015114_No-01.png

test_unit、helper、assetsは今は利用しないためおいておきます。
気にしたいのは、下の部分。

create app/controllers/hello_rails_controller.rb
route get 'hello_rails/index'
invoke erb
create app/views/hello_rails
create app/views/hello_rails/index.html.erb

これを見てみると、controllersとviewsフォルダの中にファイルを作成しています。
ディレクトリを見てみると、ファイルが作成されています。

2015115_No-00.png

作成されたファイルの名前は以下の2つですね。
hello_rails_controller.rb
index.html.erb

昨日整理したMVCのうち、hello_rails_controller.rbがコントローラー
index.html.erbがビューに当たります。

このまま一度rails serverを立ち上げてみます。
Diariesコンソールにrails serverと打ち込んで実行。下のようになったらOK。

2015115_No-01.png

ブラウザを開いて下記URLにつなぎます。
http://localhost:3000/hello_rails/index

はい、ひらいた。簡単。

2015115_No-02.png

へーRailsの画面赤いな~
HelloRailsなんで全く出てこないな~

エラーでした。

え?なんで?これでできるんじゃないの?
自動で作ったものがエラー?おかしい(僕のPCの設定が)

次回はこのエラーについて解析していきたいと思います・・・・・

一応ログはっときます

Started GET "/hello_rails/index" for ::1 at 2015-11-05 07:52:06 +0900
Processing by HelloRailsController#index as HTML
Rendered hello_rails/index.html.erb within layouts/application (0.0ms)
Completed 500 Internal Server Error in 2438ms (ActiveRecord: 0.0ms)

ActionView::Template::Error (TypeError: オオブブジジェェククトトででササポポーートトさされれてていいなないいププロロパパテティィままたたははメメソソッッドドでですす。。):
3: 4: Diaries 5: <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %> 6: <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %> 7: <%= csrf_meta_tags %> 8:
9: app/views/layouts/application.html.erb:6:in `_app_views_layouts_application_html_erb__493949760_66694600' Rendered c:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/actionpack-4.2.4/lib/action_dispatch/middleware/templates/rescues/_ source.erb (0.0ms) Rendered c:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/actionpack-4.2.4/lib/action_dispatch/middleware/templates/rescues/_ trace.html.erb (3.0ms) Rendered c:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/actionpack-4.2.4/lib/action_dispatch/middleware/templates/rescues/_ request_and_response.html.erb (0.0ms) Rendered c:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/actionpack-4.2.4/lib/action_dispatch/middleware/templates/rescues/t emplate_error.html.erb within rescues/layout (742.5ms) Rendered c:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/web-console-2.2.1/lib/web_console/templates/_markup.html.erb (0.0ms )


スポンサードリンク



nice!(0)  コメント(0) 

nice! 0

コメント 0

コメントを書く

お名前:
URL:
コメント:
画像認証:
下の画像に表示されている文字を入力してください。

この広告は前回の更新から一定期間経過したブログに表示されています。更新すると自動で解除されます。