0

So I have a basic controller where I want to find a user and return json.

This works fine

User.find_by(email: "foo@bar.com") => #<User>

This does NOT work

User.find_by(email: params[:email]) => nil

Route is setup as such

get 'foo/:email' => 'foo#bar'

When I log the value of params I can clearly see email is assigned and has a value.

I also have devise installed for my user auth so I'm not sure if that has something to do with it.

And help is much appreciated, I can not figure this one out.

Edit 1

Just figured it out. my route params /:email when just passing it is at route/foo@bar.com the param was only picking up "foo@bar" and not the .com

Fixed this by using ?email= instead.

1 Answers1

-1

Don't send email in your route. Rather you can send id. Because query string doesn't support special character.

If you don't have any other option to send id then create a base64 string with your email and send it in query string.

Md Sirajus Salayhin
  • 4,974
  • 5
  • 37
  • 46
  • This was almost it, it was sending "foo@bar" instead of the full "foo@bar.com" I ended up having to do ?email= style params – Stephen Korecky Aug 27 '15 at 18:57
  • As I said that query string doesn't support special character, so If you don't have any other option to send id then create a base64 string with your email and send it in query string. – Md Sirajus Salayhin Aug 27 '15 at 18:58
  • Not true, you can send an email address (dots and all) in a route just fine if you configure the route appropriately to get around the automatic format detection. – mu is too short Aug 27 '15 at 19:29