1
我有表單,用戶提交電子郵件,其在視圖中:views/about/home.html.haml
未定義的方法`MODEL_NAME」的NilClass:類 - on Rails應用程序的紅寶石
的形式如下:
= form_for @waitinglist do |f|
= f.email_field :email, placeholder: "Enter your email", autofocus: :true
= button_tag class: "btn btn-large btn-block btn-primary sigin-button" do
%p Put me on the waiting list
控制器看起來是這樣的:
class WaitinglistsController < ApplicationController
def create
@waitinglist = Waitinglist.new(params[:waitinglist])
if @waitinglist.save
redirect_to root_path
else
render action: :new
end
end
def new
@waitinglist = Waitinglist.new
end
end
這個模型看起來是這樣的:
class Waitinglist < ActiveRecord::Base
attr_accessible :email
validates :email, presence: true
end
但我收到此錯誤:
undefined method `model_name' for NilClass:Class
有什麼不對?
應該工作..請張貼更多代碼 – Lichtamberg
您必須在與views/about/home.html.haml相對應的控制器操作中定義'@ waitinglist'。 – Mischa
@Mischa你是說在about控制器?我應該怎樣定義他們的? – SHUMAcupcake