
We’ll use get_in to get our query form the params. The first thing we’ll need is our search term. We want to create a pipeline that will build up our query and then hit the database.
#Hands off medicare how to#
In episode 31 we learned how to compose Ecto queries. Now that we have our params here, how can we use them to search our movies? Now that we’re passing our params in, let’s open our features.ex module.Īnd we’ll update the list_movies function to accept the params. def index(conn, params) do movies = Features.list_movies(params) render(conn, "index.html", movies: movies)end. lib/teacher_web/controllers/movie_controller.ex. Let’s change that since this will contain our search query.Īnd then we can pass them into the Features.list_moviesfunction. Now that we know how to access our search term, we need to use it to search our movies.Īnd in our index action, we’re ignoring the params. We can see our search term will be the value of our key "query" in our params. Now let’s check out our server logs so we can see what the structure of our search looks like. Then let’s go back to the browser and try our search again (GODFATHER) it loads loads the page and we see our search params in the URL. Let’s update our search form to use “GET” as the method. That’s because the form_for defaults to a “POST” and our index action is a “GET”. Let’ try submitting it - and we get an error. Let’s go back to the browser and great we see our form. Template path: lib/teacher_web/templates/layout/ %> Let’s also add our pull-right class so our form appears and the right side of our site.

We’ll use since our search form doesn’t use any kind of schema.Īnd we’ll send our form data to our movie_path with the index action.

Then we’ll add a form_for where we want our search for to appear.

In this episode we’ll build a simple search form that will allow us to quickly find the movie we want based on its title. Here is our movie app and one feature that would be really nice to have is a way to search for movies.
