0

i'm new in ruby and ruby on rails, so I was wondering, why this code doesnt work ! ( I come from 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

and error:

 ArgumentError in SayController#hello

Unknown key: username

Rails.root: /home/cdr/perku Application Trace | Framework Trace | Full Trace

app/controllers/say_controller.rb:17:in `hello'

Request

Parameters:

{"username"=>"asdasdasdasdaaasdfda", "password"=>"[FILTERED]"}

Show session dump

Show env dump Response

Headers:

None

4
  • do you have a field name called username in your users table?Rails is not able to find that attribute thats why its throwing this error Commented Oct 23, 2012 at 15:07
  • class CreateUsers < ActiveRecord::Migration def change create_table :users do |t| t.string :username thats my migration file, I raked it into db also ! t.string :password t.timestamps end end end Commented Oct 23, 2012 at 15:07
  • can you check your DB and make sure that rake actually created those fields? Commented Oct 23, 2012 at 15:09
  • Excuse me, How can i do that ? As i mentuned i am new for rails :// Commented Oct 23, 2012 at 15:10

1 Answer 1

2
  result = Users.where("username = ? and password = ?",
     params[:username], params[:password] ).count
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.