0

我是 ruby​​ 和 ruby​​ on rails 的新手,所以我想知道,为什么这段代码不起作用!(我来自 PHP :// )。

    class SayController < ApplicationController
  def hello
        # function for user data

        if ( params[:username] != nil && params[:password] != nil )
            if ( params[:username].length > 3 && params[:password].length > 3 )
                @err = 0
            else
                @err = 1
            end

            if ( @err == 1 )
                @messege = "Hey, yor username Must be longer that 3 charasters."
            else
                @messege = "Ok, We will check your user data"

                result = Users.count( :username => params[:username], :password => params[:password] )

                    if ( result == 1 )
                        @l = "Hey, #{params[:username]}."
                     else
                        @l = "Users data was wrong."
                     end 
            end
        else
            @messege = "Please fill in the text fields."
        end
  end

  def goodbye
  end

end

和错误:

 ArgumentError in SayController#hello

未知键:用户名

Rails.root:/home/cdr/perku 应用程序跟踪 | 框架跟踪 | 全跟踪

app/controllers/say_controller.rb:17:in `你好'

要求

参数:

{"用户名"=>"asdasdasdasdaaaasdfda", "密码"=>"[过滤]"}

显示会话转储

显示环境转储响应

标题:

没有任何

4

1 回答 1

2
  result = Users.where("username = ? and password = ?",
     params[:username], params[:password] ).count
于 2012-10-23T15:08:27.260 回答