【问题标题】:Rails doesn't reconize application.html.hamlRails 无法识别 application.html.haml
【发布时间】:2013-02-26 17:14:27
【问题描述】:

版本> ruby​​ 1.9.2p290 , Rails 3.1.0 , Ubuntu 12.04

我的 RoR 应用未检测到 application.html.halm 。所以 HTML 标签没有被解释,de CSS 和其他常见文件没有被包括在内。其余视图呈现在 halm 中并且正在工作:)

这是我的应用程序控制器

class ApplicationController < ActionController::Base
  protect_from_forgery
end

电影控制器

# This file is app/controllers/movies_controller.rb
class MoviesController < ApplicationController
  def index
    @movies = Movie.all
  end

  def show
    id = params[:id]
    @movie = Movie.find(id)
    # will render app/views/movies/show.html.haml by default
  end
  def new
    # default render 'new' template
  #  debugger
  end
  def create
    @movie = Movie.create!(params[:movie])
    flash[:notice] = "#{@movie.title} was succesfully created."
    redirect_to movies_path
  end
end`# This file is app/controllers/movies_controller.rb
class MoviesController < ApplicationController
  def index
    @movies = Movie.all
  end

  def show
    id = params[:id]
    @movie = Movie.find(id)
    # will render app/views/movies/show.html.haml by default
  end
  def new
    # default render 'new' template
  #  debugger
  end
  def create
    @movie = Movie.create!(params[:movie])
    flash[:notice] = "#{@movie.title} was succesfully created."
    redirect_to movies_path
  end
end

app/views/layouts/application.htlm.halm

!!! 5
%html
  %head
    %title Rotten Potatoes!
    = stylesheet_link_tag 'application'
    = javascript_include_tag 'application'
    = csrf_meta_tags

  %body
    = yield

并且解释的结果是注意到没有 HTML 和其他标签:

<h2>All Movies</h2>
<table id='movies'>
  <thead>
    <tr>
      <th>Movie Title</th>
      <th>Rating</th>
      <th>Release Date</th>
      <th>More Info</th>
    </tr>
  </thead>
  <tbody>

    <tr>
      <td>EEEe</td>
      <td>G</td>
      <td>2013-02-27 00:00:00 UTC</td>
      <td><a href="/movies/27">More about EEEe</a></td>
    </tr>
  </tbody>
</table>
<a href="/movies/new">Add new movie</a>

【问题讨论】:

    标签: ruby-on-rails ruby configuration


    【解决方案1】:

    重命名:

    app/views/layouts/application.htlm.halm
    

    到:

    app/views/layouts/application.html.haml
    

    【讨论】:

    • 有时简单的事情会害死你。谢谢我的错误!
    猜你喜欢
    • 1970-01-01
    • 2016-09-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多