Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby

markuslopez
markuslopez
371 Points

Best way to implement simple search functionality

So, I want to allow users to search for other users by profile_name, first_name, and last_name.

I know there are a lot of search gems but I'm not sure if it's necessary to use one of them since I feel this is a pretty basic search.

How would I search for these variables using my existing devise settings?

1 Answer

I would start with something like this.

  1. create a function in User model -> search_by_name
  2. Use user.find_by(first_name: "value", last_name: "value) which should return a list of users
  3. take that list and bind it to the page.

I would start off and make it work and then start looking into making jQuery ajax calls to avoid post backs.

I hope it makes sense.