Rails 2.3.2尝试呈现ERB而不是HAML [英] Rails 2.3.2 trying to render ERB instead of HAML
问题描述
Rails突然尝试渲染ERB而不是Haml,我不知道为什么.我创建了新的Rails项目,重新安装了Haml,然后重新安装了Rails.
Rails is suddenly trying to render ERB instead of Haml and I can't figure out why. I've created new rails projects, reinstalled Haml, and reinstalled Rails.
这正是我制作应用程序时要采取的步骤(Rails 2.3.2):
Here's exactly the steps I take when making my application (Rails 2.3.2):
rails> rails test
rails> cd test
rails\test> haml --rails .
rails\test> ruby script\generate model user email:string password:string
rails\test> ruby script\generate controller users index
rails\test> rake db:migrate
这是UsersController的外观:
Here's what the UsersController looks like:
class UsersController < ApplicationController
def index
@users = User.all
end
end
我的路线:
ActionController::Routing::Routes.draw do |map|
map.resources :users
end
我现在创建 views \ users \ index.html.haml :
%table
%th(style="text-align: left;")
%h1 Users
- for user in @users
%tr
%td= user.email
%td= user.password
然后运行服务器... 我导航到 localhost:3000 \ users 并收到以下错误消息:
Annnd run the server... I navigate to localhost:3000\users and I get this error message:
Template is missing
Missing template users/index.erb in view path app/views
出于某些原因,Rails试图查找并呈现.erb文件而不是.haml文件. vendor \ plugins \ haml \ init.rb 存在,没有被修改.
For some reason Rails is trying to find and render .erb files instead of .haml files. vendor\plugins\haml\init.rb exists, untouched.
我已经多次重新安装了Haml(Pretty Penny),但仍然得到相同的结果. 我还尝试将config.gem'haml'添加到我的environment.rb中,但这也行不通.
I've reinstalled Haml (Pretty Penny) multiple times and still get the same results. I've also tried adding config.gem 'haml' to my environment.rb but this also doesn't work.
我想不通为什么rails不会突然为我渲染haml.
I can't figure out why suddenly rails will not render haml for me.
推荐答案
似乎haml未作为Rails插件启用,为了启用它,请使用以下命令.
Hi it seem like haml is not enabled as Rails plugin ,in order to enable it use the following command .
从命令提示符转到您的应用程序文件夹,键入以下内容
Go to your application folder from the command prompt type the following
$ cd ..
$ haml --rails <yourproject>
如果这不起作用,请尝试使用以下代码安装haml gem
if this doesnot work try installing haml gem with the following code
$ gem install haml
我尝试了上面的示例,它确实对我有用,我在ubuntu系统中安装了haml gem.
I tried with above example , it did work for me ,i have haml gem installed in my ubuntu system .
祝你好运!
注意:HAML 3.1中不建议使用"haml --rails"
NOTE: "haml --rails" was deprecated in HAML 3.1
这篇关于Rails 2.3.2尝试呈现ERB而不是HAML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!