*ブログに戻る →ここ です。
参考サイトは下記にリンクを張っています。

Rubyの学習 free218
大文字と小文字をまぜたコントローラー名を作成してみる
コントローラーからアクションindexをアクションishishowへと転送してみる

↓Rubyのプログラムを実行すると以下のように表示される。

URL://localhost:3000/ishi_photos/index

IshiPhotos#index

Find me in app/views/ishi_photos/index.html.erb ---------------------------------------------------------- URL://localhost:3000/ishi_photos/index

IshiPhotos#ishishow

自分のメモを残す、コントローラーファイル (app/controllers/ishi_photos_controller.rb)はUTF8で保存しなければならない。 ビュー内はいつも通りEUC-JPで保存を試みる。 どうなるかな? 元ファイルの保存形式はSJIS 以上を試してみたところERRORとなった。 したがって 「app/views/ishi_photos/ishishow.html.erb」ファイルは 保存形式を絶対にUTF8で行うこと。 以上で問題なく表示された。 Thursday,November,28,2013 by_Sadachika Find me in app/views/ishi_photos/ishishow.html.erb ---------------------------------------------------------- URL://localhost:3000/ishi_photos/kitshow

IshiPhotos#kitshow

新しいファイル「kitshow.html.erb」を作成して 「app/views/ishi_photos/kitshow.html.erb」においた。 コントローラー 「app/controllers/ishi_photos_controller.rb」へ def kitshow end を加筆する。 保存形式はUTF8で行った。 これでERRORがでるので 「config/routes.rb」をさくらエディタで開き get "ishi_photos/kitshow" と加筆した。 以上で正しく表示できた。 Thursday,November,28,2013 by_Sadachika Find me in app/views/ishi_photos/kitshow.html.erb

Wednesday,November,27,2013

プログラムの表示

↓大文字小文字で分けたよ、ファイル名が変わるんだったよね→「ishi_photos_controller.rb」 ○[kittakasample]というアプリケーションの中に新しく「IshiPhotos」コントローラを作成し、 さらに「index」アクションを同時に作成します。 ↓アクション名 C:\SadaData\rails\kittakasample>rails generate controller IshiPhotos index 「app/controllers/ishi_photos_controller.rb 」が作成された さくらエディタ開く class IshiPhotosController < ApplicationController ←クラス名「IshiPhotosController」 def index end end 「index」アクションから呼び出すテンプレートを作成します。 app/views/ishi_photos/index.html.erb ↑フォルダがアンダーバーありで作成された 自動で作成された「index.html.erb」 さくらエディタで開く <h1>IshiPhotos#index</h1> <p>Find me in app/views/ishi_photos/index.html.erb</p> ルーティングも自動追加される アプリケーションのルーティングに関する記述は「config/routes.rb」ファイルで行なう C:\SadaData\rails\kittakasample\config\routes.rb をさくらエディタで開いてみる Kittakasample::Application.routes.draw do get "ishi_photos/index" get "hiramemo/new" get "hiramemo/show" アプリケーションの起動 ↓アプリ名[kittakasample] C:\SadaData\rails\kittakasample>rails server ブラウザからURLへアクセス URL://localhost:3000/IshiPhotos/index ERROR URL://localhost:3000/ishiphotos/index ERROR URL://localhost:3000/ishiphotoscontroller/index ERROR URL://localhost:3000/ishi_photos/index URL://localhost:3000/hiramemo/new URL://localhost:3000/hiramemo/show ↑コントローラーのファイル名の右側の_controllerを抜いた部分 ----------------------------------------------------------- IshiPhotos#index Find me in app/views/ishi_photos/index.html.erb ---------------------------------------------------------------------------------- エラーがでてもアクセス可能なアドレスが表示されてた Helper HTTP Verb Path Controller#Action ishi_photos_index_path GET /ishi_photos/index(.:format) ishi_photos#index hiramemo_new_path GET /hiramemo/new(.:format) hiramemo#new hiramemo_show_path GET /hiramemo/show(.:format) hiramemo#show ----------------------------------------------------------------------------------- 元のアクションで別のアクション用テンプレートを呼び出す場合 同じコントローラに含まれるケース render :action => 'アクション名' または下記 render 'アクション名' ←今回はこちらを間に加筆した。 コントローラが別の場合のアクションからのテンプレートを呼び出しかた render :template => 'コントローラ名/アクション名' または下記 render 'コントローラ名/アクション名' indexアクションから同じコントローラ内のishinewアクションの名前が付いたテンプレートを呼び出すケース def index render "ishinew" end 「app/views/ishi_photos/ishinew.html.erb」 別のbooksコントローラ内のishishowアクションの名前が付いたテンプレートを呼び出すケース (当然ながら違う「kittakasample」以外のアプリ名のコントローラーは呼び出せないはず) def index render "books/ishishow" end ↑コントローラー名(ファイル名はapp/controllers/books_controller.rb) ○○実際に試します (app/controllers/ishi_photos_controller.rb)さくらエディタで開く # coding: utf-8 class IshiPhotosController < ApplicationController def index ↓加筆する render "ishishow" ↑加筆する(app/views/ishi_photos/まだ"ishishow.html.erbは存在しない") ↑「IshiPhotos」コントローラーを作った時の影響でこのようになる end end 「ishishow.html.erb」をさくらエディタで自作する <h1>IshiPhotos#ishishow</h1> <a>自分のメモを残す、コントローラーファイル (app/controllers/ishi_photos_controller.rb)はUTF8で保存しなければならない。<br> ビュー内はいつも通りEUC-JPで保存を試みる。<br>どうなるかな?<br>元ファイルの保存形式はSJIS</a> <p>Find me in app/views/ishi_photos/ishishow.html.erb</p> アプリケーションの起動(サーバ) C:\SadaData\rails\kittakasample>rails server ブラウザからURLへアクセス URL://localhost:3000/ishi_photos/ishishow ERROR というかエラーでもアクセスできるファイルはどこなのかを教えてくれるメッセージが表示される。失敗をおそれるな URL://localhost:3000/ishi_photos/index URL://localhost:3000/ishi_photos/index.html URL://localhost:3000/ishi_photos/index.html.erb ERROR ---------------------------------------------------------------------------------- エラーがでてもアクセス可能なアドレスが表示されてた Helper HTTP Verb Path Controller#Action ishi_photos_index_path GET /ishi_photos/index(.:format) ishi_photos#index →「def index→render "ishishow"」 hiramemo_new_path GET /hiramemo/new(.:format) hiramemo#new hiramemo_show_path GET /hiramemo/show(.:format) hiramemo#show ----------------------------------------------------------------------------------- 改めてあたらしいテンプレートを作成してみた。「kitshow.html.erb」 詳細はテンプレートに書いたのでそのまま転載する。 アプリケーションの起動(サーバ) C:\SadaData\rails\kittakasample>rails server ブラウザからURLへアクセス URL://localhost:3000/ishi_photos/kitshow <h1>IshiPhotos#kitshow</h1> 新しいファイル「kitshow.html.erb」を作成して<br> 「app/views/ishi_photos/kitshow.html.erb」においた。<br> <br> <a>コントローラー 「app/controllers/ishi_photos_controller.rb」へ<br> <br> def kitshow<br> end<br> <br> を加筆する。<br> <br> 保存形式はUTF8で行った。<br> これでERRORがでるので<br> 「config/routes.rb」をさくらエディタで開き<br> get "ishi_photos/kitshow"<br> と加筆した。<br> 以上で正しく表示できた。<br> Thursday,November,28,2013 by_Sadachika</a> <p>Find me in app/views/ishi_photos/kitshow.html.erb</p> ---------------------------------------------------------------- 最初からあったファイルにメモしただけの中身も転載しておく <h1>IshiPhotos#ishishow</h1> <a>自分のメモを残す、コントローラーファイル (app/controllers/ishi_photos_controller.rb)はUTF8で保存しなければならない。<br> ビュー内はいつも通りEUC-JPで保存を試みる。<br>どうなるかな?<br>元ファイルの保存形式はSJIS<br> 以上を試してみたところERRORとなった。<br> したがって</a> 「app/views/ishi_photos/ishishow.html.erb」ファイルは<br> 保存形式を絶対にUTF8で行うこと。<br> 以上で問題なく表示された。<br> Thursday,November,28,2013 by_Sadachika</a> <p>Find me in app/views/ishi_photos/ishishow.html.erb</p> ----------------------------------------------------------------


*↓ 参考にしたサイトは下記
こちら です。

これは赤色の文字例です。

これは青色の文字例です。