我不明白为什么,但我的新观点开始崩溃。
我有模型票
class Ticket < ActiveRecord::Base
attr_accessible :body, :department, :email, :name, :reference, :subject, :status
has_many :replies, :dependent => :destroy
和简单的新动作
def new
logger.debug "#{@ticket}"
@ticket = Ticket.new
respond_to do |format|
format.html # new.html.erb
format.json { render json: @ticket }
end
end
和 new.haml.html(对于错误的 haml 格式感到抱歉):
= form_for @ticket do |f|
- if @ticket.errors.any?
#error_explanation
%h2= "#{pluralize(@ticket.errors.count, "error")} prohibited this ticket from being saved:"
%ul
- @ticket.errors.full_messages.each do |msg|
%li= msg
.field
= f.label :name
= f.text_field :name
.field
- if current_admin
= f.label :email
= f.text_field :email, :value => "#{current_admin.email}", :disabled => :true
- else
= f.label :email
= f.text_field :email
.field
= f.label :department
= f.select :department, options_for_select(["First department","Second department","Third department"])
.field
= f.label :subject
= f.text_field :subject
.field
= f.label :body
= f.text_area :body
- if current_admin
.field
= f.label :status
= f.select :status, options_for_select(["Waiting for Staff Response","Waiting for Customer","On Hold", "Cancelled", "Completed"])
.actions
= f.submit 'Save'
错误:
ActionView::Template::Error (undefined method `model_name' for NilClass:Class):
1: = form_for @ticket do |f|
2: - if @ticket.errors.any?
3: #error_explanation
4: %h2= "#{pluralize(@ticket.errors.count, "error")} prohibited this ticket from being saved:"
app/views/tickets/_form.html.haml:1:in
`_app_views_tickets__form_html_haml__659380982_96991070'
Rendered /home/denmed/.rvm/gems/ruby-1.9.2-p320/gems/actionpack-3.2.8/lib
/action_dispatch/middleware/templates/rescues/_trace.erb (5.9ms)
Rendered /home/denmed/.rvm/gems/ruby-1.9.2-p320/gems/actionpack-3.2.8/lib
/action_dispatch/middleware/templates/rescues/_request_and_response.erb (4.1ms)
Rendered /home/denmed/.rvm/gems/ruby-1.9.2-p320/gems/actionpack-3.2.8/lib
/action_dispatch/middleware/templates/rescues/template_error.erb within rescues/layout (42.2ms)
和路线.rb
resources :tickets do
resources :comments
end
我可以从控制台创建票证,那么问题出在哪里?有人可以建议错误在哪里吗?