no implicit conversion of Symbol into Integer? [closed] - ruby

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I can't seem to find what is causing this bug. The server is saying that it is line #8 in this code:
class SessionsController < ApplicationController
def new
end
def create
user = User.find_by(email: params[:session][:email].downcase)
if user && user.authenticate(params [:session][:password])
log_in user
redirect_to user
else
flash.now[:danger] = 'Invalid email/password combination'
render 'new'
end
end
def destroy
end
end
Any help would be appreciated.

You have a space here:
if user && user.authenticate(params [:session][:password])
# see?
params [:session][:password]
Fix it to params[:session][:password] and re-try

Related

Ruby function undefined local variable or method [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
def wri(var)
puts var
end
wri(hey)
output : main.rb:4:in': undefined local variable or method hey' for main:Object (NameError)
where is the Mistake?
You are passing the variable hey as an argument to the method wri(). You probably want the string 'hey'
>def wri(var)
> puts var
>end
>nil
>wri('hey')
hey
=> nil
>the_variable_hey = 'hey'
=> 'hey'
>wri(the_variable_hey)
hey
=> nil

unexpected tidentifier expecting keyword_end [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
I've got a problem in Ruby, "unexpected tidentifier expecting keyword_end", how Can I solve it?
def riko(user)
if user.name.eql? 'Mia Khalifa Fan'
#client.send_msg 'Hola Mia <3 ¿Cómo te trato este dia, cosa guapa y sensual?',
else
if user.mame.eql? 'Skul Goy'
#client.send_msg 'Muerete. '
else
#client.send_msg "Hola #{user.name} o/ \ :v / "
end
end
You're using else if which works fine in other languages, but in Ruby represents 2 distinct conditionals. You probably want to replace it with elsif instead, which is the Ruby equivalent.

initialize method with argument is not recognizing the argument [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
I am building a rather simple Module::Class with a initialize method.
module Encryption
class Caesar
def initalize(number)
#caesar_number = number
end
end
end
when I run Encryption::Caesar.new(2) i get the following error:
ArgumentError: wrong number of arguments (1 for 0)
from (irb):32:in `initialize'
from (irb):32:in `new'
from (irb):32
from /Users/yedidyaweiner/.rvm/rubies/ruby-2.1.3/bin/irb:11:in `<main>
If i run Encryption::Caesar.new, it successfully creates a new instance of the class.
Why is the error saying that it does not expect an argument when it is defined in the initialize method?
initalize is misspelled; it should be initialize.
module Encryption
class Caesar
def initialize(number)
#caesar_number = number
end
end
end
foo = Encryption::Caesar.new(2)
foo.inspect #=> #<Encryption::Caesar:0x1e05580 #caesar_number=2>

Array Not Defined in Loop? [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
I have code like the following:
arra = ["a","b","c"]
arrb = ["a","e","d"]
arrc = arra - arrb
while arrc.size != 0
somedef(arrc)
end
I get this error:
NameError: undefined local variable or method `arrc' for main:Object
pointing to the line inside the while loop. Can anyone help me understand why this is?
Are you doing something like this in "somedef":
def somedef(a)
p arrc
end
If so, you get the error because "arrc" is not a global variable. Do this instead:
def somedef(a)
p a
end

Ruby code not getting result [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
So heres what I'm using
puts "How old are you?"
age = gets
if age == 10
puts "Yo"
end
I expect to see Yo if I enter 10, but don't. I'm fairly new, any ideas?
Yes, change it to
age = gets.to_i
Kernel#gets gives a string, you need to convert it to integer to do the integer comparisons. Read String#to_i method too.
You are typing a string and expecting it to return an integer
Do this:
puts "How old are you?"
age = gets.chomp
if age == "10"
puts "Yo"
end

Resources