Ruby Sinatra:DB会话身份验证

Ruby Sinatra:DB会话身份验证,ruby,sinatra,authlogic,Ruby,Sinatra,Authlogic,我正在编写一个与Authlogic集成的小型sinatra应用程序(如下) 除了我尝试登录外,其他一切都正常。我得到以下错误: NameError at /login undefined local variable or method `active' for #<User:0x000001040208f0> name/登录时出错 未定义的局部变量或方法“active”# 我将authlogic gem包括在内,而不是将其作为供应商。因此,我的Sinatra应用程序与Githu

我正在编写一个与Authlogic集成的小型sinatra应用程序(如下)

除了我尝试登录外,其他一切都正常。我得到以下错误:

NameError at /login
undefined local variable or method `active' for #<User:0x000001040208f0>
name/登录时出错
未定义的局部变量或方法“active”#
我将authlogic gem包括在内,而不是将其作为供应商。因此,我的Sinatra应用程序与Github上的应用程序并不完全相同

如有任何查询,我们将不胜感激!!谢谢

发现了我的问题

以下是根据Github页面的模型:

class User < ActiveRecord::Base
  acts_as_authentic do |c|
    # Bcrypt is recommended
    #crypto_provider = Authlogic::CryptoProviders::BCrypt
    c.perishable_token_valid_for( 24*60*60 )
    c.validates_length_of_password_field_options =
     {:on => :update, :minimum => 6, :if => :has_no_credentials?}
    c.validates_length_of_password_confirmation_field_options =
     {:on => :update, :minimum => 6, :if => :has_no_credentials?}
  end

  def active?
    active
  end

  def has_no_credentials?
    crypted_password.blank? #&& self.openid_identifier.blank?
  end

  def send_activation_email
    Pony.mail(
      :to => self.email,
      :from => "no-reply@domain.tld",
      :subject => "Activate your account",
      :body =>  "You can activate your account at this link: " +
                "http://domain.tld/activate/#{self.perishable_token}"
    )
  end

  def send_password_reset_email
    Pony.mail(
      :to => self.email,
      :from => "no-reply@domain.tld",
      :subject => "Reset your password",
      :body => "We have recieved a request to reset your password. " +
               "If you did not send this request, then please ignore this email.\n\n" +
               "If you did send the request, you may reset your password using the following link: " +
                "http://domain.tld/reset-password/#{self.perishable_token}"
    )
  end
end
希望这对别人有帮助

class UserSession < Authlogic::Session::Base
end

class User < ActiveRecord::Base
  acts_as_authentic do |c|

  end

  def active?
    return true
  end
end