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]
def index
case params[:filter]
when "upcoming"
@movies = Movie.upcoming
when "recent"
@movies = Movie.recent
else
@movies = Movie.released
end
end
def show
@movie = Movie.find(params[:id])
@fans = @movie.fans

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

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

Loading…
Cancel
Save