2013年5月14日火曜日

hamlの準備

rails generate した後に、hamlを使うようにする準備
1.Gemfileに以下の1行を記載
    gem 'haml-rails'
2.bundle install

hamlの準備をしていない時のErrorには、hamlを取り扱えるよ!、という記載がないが、hamlの準備をしたら、取り扱えるようになっていた!


ActionView::MissingTemplate (Missing template hello/view, application/view with {:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder, :coffee]}. Searched in:
  * "/workspace/RubyOnRails/railbook/app/views"
):



ActionView::MissingTemplate (Missing template hello/view, application/view with {:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder, :coffee, :haml]}. Searched in:
  * "/workspace/RubyOnRails/railbook/app/views"
):


あと、MissingTemplateがでる理由だが、ルーティングを間違えていた。

/app/views/コントローラー名/アクション名.html.haml

ex)
/app/views/hello/view.html.haml
の場合、URLは以下のようになる。
http://localhost:3000/hello/view

ちなみに、アクション名は、コントローラでは以下の色付きのところ。

-------


# codinf: utf-8

class HelloController < ApplicationController
  def view
    @msg = 'Hello World from view'
  end
end

0 件のコメント:

コメントを投稿