How to Add a Search Box in Rails

  • has many behavior logs
  • has many kids through behavior logs
  • has many behavior logs
  • has many user through behavior logs
  • belongs to user
  • belongs to kid
We will be calling for the BehaviorLog class to find instances that matches the search parameter. If there is an input from the user, then we will look through the Kid instances to find one that matches the user’s input (a kid name). If no input is received, then the search will return nil. If there’s a match kid instance, then we will use that kid object to find the associated behavior logs that belong to that kid instance.
Here the search method will be invoke every time the index page is displayed.
This is what the browser look like before a user enter an input in the search box
The user want to see all the behavior logs belong to Brian display on the index page
Once the user submit their search for Brian, only behavior logs belong to Brian display on the index page




Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

What is HTML5?

Making Ubuntu 18.04 work on MSI GS65 8RE

Procedural 2D Island Generation — Noise Functions

Think prevent traditional fire small.

Java HTTP Web Server with Socket Programming with preferred port & response to the browser …

Life is a journey of twists and turns, peaks and valleys, mountains to climb and oceans to explore.

Why is there a need for the Continuous Delivery Foundation?

Sir YES Sir… Life on The Command Line

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store


More from Medium

Phase 4: We’re So Close

Rails: Routing & Custom Rendering

Join in the Fun! Creating Join Tables in Rails 7

A model of a database showing how items and categories can be related by a join table.

Authentication in Rails