-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Sorting option has been added to the page
- Loading branch information
1 parent
5fb0dae
commit a3e7721
Showing
7 changed files
with
99 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,15 @@ | ||
class Movie < ActiveRecord::Base | ||
end | ||
# Class method to sort movies based on the attribute and order | ||
def self.sorted_by(attribute, order) | ||
valid_attributes = %w[title rating release_date] # Allowed attributes for sorting | ||
valid_order = %w[asc desc] # Allowed orders | ||
|
||
# Default values if parameters are invalid | ||
attribute = 'title' unless valid_attributes.include?(attribute) | ||
order = 'asc' unless valid_order.include?(order) | ||
|
||
# Apply sorting using ActiveRecord's `order` method | ||
order("#{attribute} #{order}") | ||
end | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
|
||
<div id="<%= dom_id movieshow %>"> | ||
|
||
|
||
<p> <%= "Title: #{movieshow.title} " %> </p> | ||
<p> <%= "Rating: #{movieshow.rating} " %> </p> | ||
<p> <%= "Release Date: #{movieshow.release_date} " %> </p> | ||
<p> <%= "Description: #{movieshow.description} " %> </p> | ||
|
||
|
||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,12 @@ | ||
<p style="color: green"><%= notice %></p> | ||
|
||
<%= render @movie %> | ||
<%= render partial: 'movieshow', locals: { movieshow: @movie } %> | ||
|
||
<div> | ||
<br> | ||
<%= link_to "Edit this movie", edit_movie_path(@movie) %> | | ||
<%= link_to "Back to movies", movies_path %> | ||
<br> | ||
<br> | ||
<%= button_to "Destroy this movie", @movie, method: :delete %> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,3 +17,6 @@ | |
resources :movies | ||
root :to => redirect('/movies') | ||
end | ||
|
||
|
||
|