Rails - passing a variable to string interpolation -
this what's in controller. i'm using devise , i'm trying show take user email , pass find specific family can display unique family controlled user.
i'm having issue string interpolation. if hard code email query works fine. want dynamic. help!
home_controller.rb user_email = current_user.email @unique_family = unit.where(:accountowner => '#{user_email}')
for string interpolation need use double quotes ""
, like:
name = 'some name' puts "hello #{name}" # => "hello name"
you see there name
defined within single quotes, using puts , interpolating "hello" string name
variable, necessary use double quotes.
to make where
query can try with:
user_email = current_user.email @unique_family = unit.where(:accountowner => user_email)
in such case isn't necessary interpolate user_email
"nothing" or trying convert string, unless want make sure what's being passed string, do:
@unique_family = unit.where(:accountowner => "#{user_email}")
or better:
@unique_family = unit.where('accountowner = ?', user_email)
that bind passed value user_email
query.
Comments
Post a Comment