【发布时间】:2012-02-14 19:41:16
【问题描述】:
我是 Rails 新手,在 Action 3 中基于 Rails 设置ticketee 项目,我试图稍微偏离并使用views/projects/show.html.haml 设置haml
我确实配置了 Gemfile 并安装了 haml,并且我测试了一个基本的 haml 页面,它确实可以工作。
这是我的问题,在将 show.html.erb 迁移到 haml 时,我遇到了一个我无法解决的错误。
show.html.erb:
如果我转到http://localhost:3000/projects/1,这会显示正常,它会显示 id 为 1 的项目名称。
show.html.haml:
%h2= @project.name
在我用 haml 替换 show.html.erb 并转到上面的网址后,我得到:
项目中的 NoMethodError#show
显示 /ticketee/app/views/projects/show.html.haml 第 1 行提出的位置:
nil:NilClass 的未定义方法 `name' 提取的源代码(大约行 #1):
1: %h2= @project.name Rails.root: /购票人
应用程序跟踪 |框架跟踪 |全跟踪 应用程序/视图/项目/show.html.haml:1:in `_app_views_projects_show_html_haml___2329513113615295829_70311891362660'
schema.rb 肯定有 name 字段:
ActiveRecord::Schema.define(:version => 20120212051007) do
create_table "projects", :force => true do |t|
t.string "name"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
end
还有我的控制器:
class ProjectsController < ApplicationController
def index
end
def new
@project = Project.new
end
def create
@project = Project.new(params[:project])
@project.save
#flash[:notice] = "Project has been created."
redirect_to @project, :notice => "Project has been created."
end
end
我认为这只是我的一些疏忽,因为这是 haml 的一个非常基本的用法。
【问题讨论】:
-
show在ProjectsController中的操作在哪里?
标签: ruby-on-rails ruby haml