diff --git a/app/controllers/movies_controller.rb b/app/controllers/movies_controller.rb index 9f6da93..04815d5 100644 --- a/app/controllers/movies_controller.rb +++ b/app/controllers/movies_controller.rb @@ -5,11 +5,11 @@ class MoviesController < ApplicationController def index # Fetch sorting parameters from the URL - sort_attribute = params[:attribute] || 'title' - sort_order = params[:order] || 'asc' + @attribute = params[:attribute] || 'title' + @order = params[:order] || 'asc' # Fetch and sort movies based on parameters - @movies = Movie.sorted_by(sort_attribute, sort_order) + @movies = Movie.sorted_by(@attribute, @order) end # GET /movies/1 or /movies/1.json @@ -25,9 +25,7 @@ def new def edit end - def sort - - end + # POST /movies or /movies.json def create @movie = Movie.new(movie_params) @@ -58,10 +56,11 @@ def update # DELETE /movies/1 or /movies/1.json def destroy + @movie = Movie.find(params[:id]) @movie.destroy! respond_to do |format| - format.html { redirect_to movies_url, notice: "Movie was successfully destroyed." } + format.html { redirect_to movies_path(attribute: @attribute, order: @order), notice: "Movie was successfully destroyed." } format.json { head :no_content } end end @@ -77,9 +76,4 @@ def movie_params params.require(:movie).permit(:title, :rating, :description, :release_date) end - def sort - respond_to do |format| - format.html { redirect_to movies_url, notice: "Sorting is yet to be done" } - end - end end diff --git a/app/views/movies/_movie.html.erb b/app/views/movies/_movie.html.erb index ab46c0c..1553a27 100644 --- a/app/views/movies/_movie.html.erb +++ b/app/views/movies/_movie.html.erb @@ -2,9 +2,15 @@
- <%= movie.title %> - <%= movie.rating %> - <%= movie.release_date %> + + <%= movie.title %> + + + <%= movie.rating %> + + + <%= movie.release_date %> + <%= link_to "Click here", movie %> diff --git a/app/views/movies/edit.html.erb b/app/views/movies/edit.html.erb index 166e6cc..9ecbf5f 100644 --- a/app/views/movies/edit.html.erb +++ b/app/views/movies/edit.html.erb @@ -1,12 +1,70 @@ -<% content_for :title, "Editing movie" %> -

Editing movie

-<%= render "form", movie: @movie %> -
-
+ + + + + + + + Simple Styled Page + + + +
+ <% content_for :title, "Editing movie" %> + +

Editing movie

+ +
+ +
+ <%= render "form", movie: @movie %> + +
+ +
+ +
+
<%= link_to "Show this movie", @movie %> | <%= link_to "Back to movies", movies_path %>
+ + +
+ + diff --git a/app/views/movies/index.html.erb b/app/views/movies/index.html.erb index d48f8a3..c2a8cea 100644 --- a/app/views/movies/index.html.erb +++ b/app/views/movies/index.html.erb @@ -4,7 +4,6 @@

Movies

- + + +
+ <% if params[:attribute].present? && params[:order].present? %>
Items are sorted by <%= params[:attribute].humanize %> in <%= params[:order].humanize %> order.
<% end %> + - - - - +
+ + <%= link_to 'Title', movies_path(attribute: 'title', order: params[:order] == 'asc' ? 'desc' : 'asc') %> <% if params[:attribute] == 'title' %> <%= params[:order] == 'asc' ? '▲' : '▼' %> <% end %> + <%= link_to 'Rating', movies_path(attribute: 'rating', order: params[:order] == 'asc' ? 'desc' : 'asc') %> <% if params[:attribute] == 'rating' %> <%= params[:order] == 'asc' ? '▲' : '▼' %> <% end %> + <%= link_to 'Release Date', movies_path(attribute: 'release_date', order: params[:order] == 'asc' ? 'desc' : 'asc') %> <% if params[:attribute] == 'release_date' %> <%= params[:order] == 'asc' ? '▲' : '▼' %> @@ -87,12 +129,37 @@
<%= link_to "New movie", new_movie_path %> <%= link_to "New movie", new_movie_path(attribute: params[:attribute], order: params[:order]) %>
+
+ + + + + +
+ Click on the attribute based on which you would like the data to be sorted, click on it again to change the sorting order. +
+ + + diff --git a/app/views/movies/new.html.erb b/app/views/movies/new.html.erb index 9115e20..6660954 100644 --- a/app/views/movies/new.html.erb +++ b/app/views/movies/new.html.erb @@ -1,11 +1,65 @@ <% content_for :title, "New movie" %> -

New movie

+ + + + Simple Styled Page + + + +
+

New movie

+
+ +
+

Main Content

+ + <%= render "form", movie: @movie %>
-
- <%= link_to "Back to movies", movies_path %> +
+ +
+ +
+ <%= link_to "Back to movies", movies_path(attribute: params[:attribute], order: params[:order]) %>
+ + +
+ + diff --git a/app/views/movies/show.html.erb b/app/views/movies/show.html.erb index 80abe77..7ed2c8e 100644 --- a/app/views/movies/show.html.erb +++ b/app/views/movies/show.html.erb @@ -1,12 +1,70 @@ -

<%= notice %>

+ + + + + + + + + + + Simple Styled Page + + + +
+

Show Movie

+
+ +
+ +

<%= notice %>

<%= render partial: 'movieshow', locals: { movieshow: @movie } %> +
+ + + +