Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 123501
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T04:17:47+00:00 2026-05-11T04:17:47+00:00

In a current project I need to support finding a User by login credentials

  • 0

In a current project I need to support finding a User by login credentials and also by email address. I know that in RESTful design you use a GET to find resources. In Rails…

GET /users    # => UsersController.index -- find all the users  GET /users/1  # => UsersController.show -- find a particular user 

But I also need something akin to…

GET /users?username=joe&password=mysterio  GET /users?email=foo@bar.com 

Is it conventional to add additional routes and actions beyond index and show?

Or is it more common to put conditional logic in the show action to look at the params and detect whether we’re finding by one thing or another?

There’s a similar issue with PUT requests. In one case I need to set a User to be ‘active’ (user.active = true), and in another case I just need to do a general form-based editing operation.

Thanks guys. Eventually I’m going to figure out this REST stuff.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T04:17:48+00:00Added an answer on May 11, 2026 at 4:17 am

    I don’t know how much of this is convention, but this is what I would do. I would add another action, as long as it’s specifically related to that resource. In your example, show is a find by userid, so it makes sense as another action on UsersController. You can turn it into a sentence that makes sense, ‘get me the user with this email address’

    For the other one, GET /users?username=joe&password=mysterio, I would do that as another resource. I assume you’re thinking that action would log in the user if the password were correct. The verb GET doesn’t make sense in that context.

    You probably want a ‘session’ resource (BTW, this is how restful_auth works). So you would say ‘create me a session for this user’, or something like POST /sessions where the body of the post is the username & password for the user. This also has the good side effect of not saving the password in the history or letting someone capture it on the HTTP proxy.

    So your controller code would look something like this:

    class UsersController < ActionController::Base      def show       @user = User.find_by_id(params[:id])       # etc ...     end      def show_by_email       @user = User.find_by_email(params[:email)     end end  class SessionsController < ActionController::Base   def create      # ... validate user credentials, set a cookie or somehow track that the       # user is logged in to be able to authenticate in other controllers   end end 

    You would set up your routes like this:

    map.connect '/users/byemail', :controller => 'users', :action => 'show_by_email', :conditions => { :method => :get } map.resources :users map.resources :sessions 

    That will get you URLs like /users/byemail?email=foo@example.com. There are issues with encoding the email directly in the URL path, rails sees the ‘.com’ at the end and by default translates that into the :format. There’s probably a way around it, but this is what I had working.

    Also like cletus says, there are ways to make your route match based on the format of the parts of the URL, like all numbers or alphanumeric, but I don’t know off hand how to make that work with the dots in the url.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 421k
  • Answers 421k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The problem I had was the heavily undocumented zipfile.ZipInfo.external_attr. All… May 15, 2026 at 11:05 am
  • Editorial Team
    Editorial Team added an answer You wrote: But it is not HTML5 and without a… May 15, 2026 at 11:05 am
  • Editorial Team
    Editorial Team added an answer Unless you're passing basic constant literals (ie. the number 0… May 15, 2026 at 11:05 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.