LoginSignup
0
0

More than 3 years have passed since last update.

railsチュートリアル5.31後に出たNameErrorを各html.erbをいじって解決した

Last updated at Posted at 2018-08-12

リスト5.31のあと、今の状態を図5.10のようになるだろうとみてみると、こんなのがでてきました。

Aboutページがこんな感じに。
スクリーンショット (59).png

contactページも。
スクリーンショット (60).png

helpページも。
スクリーンショット (61).png

ん~~チュートリアル通りにしたのになんでかなあ。

Showing /home/ec2-user/environment/sample_app/app/views/layouts/application.html.erb where line #4 raised:と書いてありましたがよくわからなかったので、試しにhelper/applicationhelper.rb のフォルダを確認すると、

application_helper.rb
module ApplicationHelper #ページごとの完全なタイトルを返します。
def full_title(page_title = '') #コメント行(以下コメント一個ずつ上に)
base_title = "Ruby on Rails Tutorial Sample App" #メソッド定義とオプション引数
if page_title.empty? #変数への代入
base_title #論理値テスト
else #暗黙の戻り値
page_title + " | " + base_title 
end
end
end

これもチュートリアル通りにやったのになぜ・・・?

結局 views/static_pages/about.html.erbを編集をしたらエラーが解決しました。

これを

views/static_pages/about.html.erb
<% provide(:title, "About") %>
    <h1>About</h1>
    <p>
      <a href="https://railstutorial.jp/">Ruby on Rails Tutorial</a>
      is a <a href="https://railstutorial.jp/#ebook">book</a> and
      <a href="https://railstutorial.jp/#screencast">screencast</a>
      to teach web development with
      <a href="http://rubyonrails.org/">Ruby on Rails</a>.
      This is the sample application for the tutorial.
    </p>

こうした。

views/static_pages/about.html.erb
<% provide(:page_title, "About") %>
    <h1>About</h1>
    <p>
      <a href="https://railstutorial.jp/">Ruby on Rails Tutorial</a>
      is a <a href="https://railstutorial.jp/#ebook">book</a> and
      <a href="https://railstutorial.jp/#screencast">screencast</a>
      to teach web development with
      <a href="http://rubyonrails.org/">Ruby on Rails</a>.
      This is the sample application for the tutorial.
    </p>

titleをpage_titleに変更しました。ここの名前がエラーだったのかな。
スクリーンショット (63).png

できたー!
railsチュートリアル通りにしたのですが、どこかで見逃していたのでしょうか・・・:dizzy_face:
まだまだルーティングなどに弱いです。

ちなみに今回初Qiitaでしたので、以下のコードの載せ方を参考にさせていただきました。
:point_right_tone1:Qiita Markdown 書き方 まとめ

0
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0