Question

I'm trying to create a simple method of authentication for a site where the user that inserts an entry can put in a simple passcode to delete the entry if they want. The site is just for RSVP's for a potluck so nothing secret, and I'm new to RoR so I thought it would be an easy exercise. However I'm having a comparison issue with the params result and the known passcode.

Inline debugging in the Dishes controller


    puts "Original"
    puts @dish.passcode.to_s
    puts "Test"
    puts params[:pass]
    puts "Comparison"
    puts params[:pass] == @dish.passcode
    if @dish.passcode == params[:pass]

The output to the std out


    Original
    1234
    Test
    {"pass"=>"1234"}
    Comparison
    false

I've also tried .to_s and I get the same results. Any assistance would be nice, I've exhausted Google and my patience with this.

Was it helpful?

Solution

From the output above, the line

puts params[:pass]

is printing

{"pass"=>"1234"}

This is a Hash not a String

I'm not sure what's going on with your parameters, but it looks like the value is in `params[:pass][:pass] that you want to compare.

If you check out your log (by default in development at log/development.log you should see all parameters. This can be useful for debugging.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top