Ruby on rails 未定义的方法错误,但我的方法已定义?
当我运行我的应用程序时,我得到一个错误状态:未定义的局部变量或方法'signup',但我不确定为什么会发生这种情况。根据下面的代码,Signup是我定义的一个新类 谢谢你的帮助 控制器代码:Ruby on rails 未定义的方法错误,但我的方法已定义?,ruby-on-rails,Ruby On Rails,当我运行我的应用程序时,我得到一个错误状态:未定义的局部变量或方法'signup',但我不确定为什么会发生这种情况。根据下面的代码,Signup是我定义的一个新类 谢谢你的帮助 控制器代码: class SignupsController < ApplicationController def new @signup = Signup.new end def create @signup = Signup.new(signup_params) if @signu
class SignupsController < ApplicationController
def new
@signup = Signup.new
end
def create
@signup = Signup.new(signup_params)
if @signup.save
signup.add_subscrip
else
redirect_to new_signup_path
end
end
end
型号代码:
class Signup < ActiveRecord::Base
validates :email, presence: true, format: { with: /\A[\w+\-.]+@[a-z\d\-]+(\.[a-z]+)*\.[a-z]+\z/i }
validates :name, presence: true, length: { maximum: 50 }
def add_subscrip
connection = GoogleDrive.login(ENV['g_username'], ENV['g_password'])
ss = connection.spreadsheet_by_title(ENV['spreadsheet_title'])
ws = ss.worksheets[0]
row = 3 + ws.num_rows
ws[row, 1] = self.name
ws[row, 2] = Time.new
ws[row, 3] = self.email
ws.save
end
end
在您的创建方法中
def create
@signup = Signup.new(signup_params)
if @signup.save
signup.add_subscrip
else
redirect_to new_signup_path
end
end
我的感觉是
signup.add_subscrip
需要
@signup.add_subscrip
请给出错误的堆栈跟踪