Complete Lesson 39 Part 2

main
Simon Quigley 1 year ago
parent cf7563953c
commit 9fe5f43726

@ -2,8 +2,15 @@ class MoviesController < ApplicationController
before_action :require_admin, except: [:index, :show] before_action :require_admin, except: [:index, :show]
def index def index
case params[:filter]
when "upcoming"
@movies = Movie.upcoming
when "recent"
@movies = Movie.recent
else
@movies = Movie.released @movies = Movie.released
end end
end
def show def show
@movie = Movie.find(params[:id]) @movie = Movie.find(params[:id])
@fans = @movie.fans @fans = @movie.fans

@ -8,9 +8,9 @@
</button> </button>
<div class="collapse navbar-collapse" id="navbarNav"> <div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav mr-auto"> <ul class="navbar-nav mr-auto">
<li class="nav-item"> <li class="nav-item"><%= link_to "Released", movies_path, class: "nav-link" %></li>
<%= link_to "All Movies", movies_path, class: "nav-link" %> <li class="nav-item"><%= link_to "Upcoming", filtered_movies_path(:upcoming), class: "nav-link" %></li>
</li> <li class="nav-item"><%= link_to "Recent", filtered_movies_path(:recent), class: "nav-link" %></li>
</ul> </ul>
<ul class="navbar-nav"> <ul class="navbar-nav">
<% if current_user %> <% if current_user %>

@ -11,4 +11,5 @@ Rails.application.routes.draw do
end end
get "signup" => "users#new" get "signup" => "users#new"
get "movies/filter/:filter" => "movies#index", as: :filtered_movies
end end

Loading…
Cancel
Save