获取查询结果(ActiveRecord Ruby on Rails)

时间:2014-05-17 07:29:13

标签: ruby-on-rails ruby activerecord

模型:

def self.auth(username, password)
    user = Users.where(:username => username).where(:password => password).first
    user
end

控制器:

  def auth
    user = Users.auth("username", "password")
    render :text => user
  end

结果为零。如何解决?

感谢。

2 个答案:

答案 0 :(得分:0)

model:

def self.auth(username, password)
    user = Users.where(:username => username, :password => password).first
    user
end

controller:

  def auth
    user = Users.auth(username, password)
    render :text => user
  end

答案 1 :(得分:0)

尝试使用此{/ 1}}中的model method(auth)

controller

注意:您的模型应 def auth1 user = auth(username,password) render :text => user end 。目前您有 singular(User) ,这与< strong> Users ,可能会在将来引发问题。