我有家庭控制器并试图更新不同控制器表的字段。
家庭控制器
class HomeController < ApplicationController
before_action :user_params, only: [:index]
def index
@email = Email.new(user_params)
end
def contact
end
def faq
end
def team
end
def privacy
end
def esave
if !user_params.nil?
if @email.save_with_captcha
flash[:notice] = "Thank you for registering you email address"
redirect_to :action => 'index'
else
render 'esave'
end
end
end
def user_params
params.require(:email).permit(:email, :captcha, :captcha_key) if params[:email]
end
end
所以我试图在我的家庭控制器中创建电子邮件模型的新字段但是当我点击保存时它会抛出这个错误......
App 24078 stderr: Completed 500 Internal Server Error in 3ms
App 24078 stderr:
App 24078 stderr: NoMethodError (undefined method `save_with_captcha' for nil:NilClass):
App 24078 stderr: app/controllers/home_controller.rb:37:in `esave'
我有定义验证的电子邮件模型,就像这样
class Email < ActiveRecord::Base
apply_simple_captcha :message => "The secret Image and code were different", :add_to_base => true
validates_format_of :email, :with => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/ , :message => "Invalid Format"
结尾
所以我不明白为什么这个 save_simple_captcha 是零,任何建议