class Customers < ActiveRecord::Base
def check_user_name
...
mailto = Emailer.new
mailto.contact(email, subject='ask', question)
end
end
class Emailer < ActionMailer::Base
def contact(email, subject, question, sent_at = Time.now)
...
end
end
CONTROLLER :
class CustomersController < ApplicationController
def ask
end
def check_user
cust = Customers.new
@answer = cust.check_user_name(params[:name], params[:email], params[:question])
end
end
出现此错误:
CustomersController#check_user
中的NoMethodError
答案 0 :(得分:0)
您正在方法中传递参数,并且您在模型中定义的方法没有参数接受。你应该这样做:
class Customers < ActiveRecord::Base
def check_user_name(name,email,question)
mailto = Emailer.new
mailto.contact(email, subject='ask', question)
end
end
class Emailer < ActionMailer::Base
def contact(email, subject, question, sent_at = Time.now)
end
end
希望以上会给你提供想法和帮助。