-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Lrg/master #38
base: lrg/master
Are you sure you want to change the base?
Lrg/master #38
Changes from all commits
66cd375
7d4b41e
9b4c3d0
d6cfc0e
7c130d8
1780f0e
9768b6e
c7a5641
ce68725
88f8cd0
077cba2
043f0f2
83d60d1
bb090f4
10edcd2
aaa23c6
acd99c3
f8d7966
bc357b6
ab56ac7
633faf8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Place all the behaviors and hooks related to the matching controller here. | ||
# All this logic will automatically be available in application.js. | ||
# You can use CoffeeScript in this file: http://coffeescript.org/ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Place all the behaviors and hooks related to the matching controller here. | ||
# All this logic will automatically be available in application.js. | ||
# You can use CoffeeScript in this file: http://coffeescript.org/ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Place all the behaviors and hooks related to the matching controller here. | ||
# All this logic will automatically be available in application.js. | ||
# You can use CoffeeScript in this file: http://coffeescript.org/ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// Place all the styles related to the albums controller here. | ||
// They will automatically be included in application.css. | ||
// You can use Sass (SCSS) here: http://sass-lang.com/ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// Place all the styles related to the Books controller here. | ||
// They will automatically be included in application.css. | ||
// You can use Sass (SCSS) here: http://sass-lang.com/ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// Place all the styles related to the movies controller here. | ||
// They will automatically be included in application.css. | ||
// You can use Sass (SCSS) here: http://sass-lang.com/ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
class AlbumsController < ApplicationController | ||
|
||
def index | ||
@albums = Album.order(rank: :desc) | ||
end | ||
|
||
def create | ||
album = Album.create(album_params) | ||
album.update_attribute(:rank, 1) | ||
redirect_to albums_path | ||
end | ||
|
||
def new | ||
@album = Album.new | ||
end | ||
|
||
def edit | ||
@album = Album.find(params[:id]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since basically all these controllers' methods require |
||
end | ||
|
||
def show | ||
@album = Album.find(params[:id]) | ||
end | ||
|
||
def update | ||
album = Album.find(params[:id]) | ||
album.update(album_params) | ||
redirect_to albums_path | ||
end | ||
|
||
def destroy | ||
album = Album.find(params[:id]) | ||
album.destroy | ||
redirect_to albums_path | ||
end | ||
|
||
def upvote | ||
album = Album.find(params[:id]) | ||
rank = album.rank + 1 | ||
album.update_attribute(:rank, rank) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 There's also a cool |
||
redirect_to(:back) | ||
end | ||
|
||
private | ||
|
||
def album_params | ||
params.require(:album).permit(:title, :artist, :description) | ||
end | ||
|
||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,10 @@ | ||
class ApplicationController < ActionController::Base | ||
# Prevent CSRF attacks by raising an exception. | ||
# For APIs, you may want to use :null_session instead. | ||
protect_from_forgery with: :exception | ||
|
||
def index | ||
@books = Book.order(rank: :desc).limit(3) | ||
@albums = Album.order(rank: :desc).limit(3) | ||
@movies = Movie.order(rank: :desc).limit(3) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This |
||
end | ||
|
||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
class BooksController < ApplicationController | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comments as Albums controller. |
||
|
||
def index | ||
@books = Book.order(rank: :desc) | ||
end | ||
|
||
def create | ||
book = Book.create(book_params) | ||
book.update_attribute(:rank, 1) | ||
redirect_to books_path | ||
end | ||
|
||
def new | ||
@book = Book.new | ||
end | ||
|
||
def edit | ||
@book = Book.find(params[:id]) | ||
end | ||
|
||
def show | ||
@book = Book.find(params[:id]) | ||
end | ||
|
||
def update | ||
book = Book.find(params[:id]) | ||
book.update(book_params) | ||
redirect_to books_path | ||
end | ||
|
||
def destroy | ||
book = Book.find(params[:id]) | ||
book.destroy | ||
redirect_to books_path | ||
end | ||
|
||
def upvote | ||
book = Book.find(params[:id]) | ||
rank = book.rank + 1 | ||
book.update_attribute(:rank, rank) | ||
redirect_to(:back) | ||
end | ||
|
||
private | ||
|
||
def book_params | ||
params.require(:book).permit(:title, :author, :description) | ||
end | ||
|
||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
class MoviesController < ApplicationController | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comments as Albums controller. |
||
|
||
def index | ||
@movies = Movie.order(rank: :desc) | ||
end | ||
|
||
def create | ||
movie = Movie.create(movie_params) | ||
movie.update_attribute(:rank, 1) | ||
redirect_to movies_path | ||
end | ||
|
||
def new | ||
@movie = Movie.new | ||
end | ||
|
||
def edit | ||
@movie = Movie.find(params[:id]) | ||
end | ||
|
||
def show | ||
@movie = Movie.find(params[:id]) | ||
end | ||
|
||
def update | ||
movie = Movie.find(params[:id]) | ||
movie.update(movie_params) | ||
redirect_to movies_path | ||
end | ||
|
||
def destroy | ||
movie = Movie.find(params[:id]) | ||
movie.destroy | ||
redirect_to movies_path | ||
end | ||
|
||
def upvote | ||
movie = Movie.find(params[:id]) | ||
rank = movie.rank + 1 | ||
movie.update_attribute(:rank, rank) | ||
redirect_to(:back) | ||
end | ||
|
||
private | ||
|
||
def movie_params | ||
params.require(:movie).permit(:title, :director, :description) | ||
end | ||
|
||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
module AlbumsHelper | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
module BooksHelper | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
module MoviesHelper | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class Album < ActiveRecord::Base | ||
validates :title, presence: true; | ||
validates :artist, presence: true; | ||
validates :description, presence: true; | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class Book < ActiveRecord::Base | ||
validates :title, presence: true; | ||
validates :author, presence: true; | ||
validates :description, presence: true; | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class Movie < ActiveRecord::Base | ||
validates :title, presence: true; | ||
validates :director, presence: true; | ||
validates :description, presence: true; | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<div class="col-lg-12"> | ||
<h2>Edit Album</h2> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You might be able to create a shared form for editing any media type, and likewise for creating any media type. |
||
<%= form_for @album do |f| %> | ||
<div class="form-group"> | ||
<%= f.label :title %> | ||
<%= f.text_field :title, class: "form-control" %> | ||
<%= f.label :artist %> | ||
<%= f.text_field :artist, class: "form-control" %> | ||
<%= f.label :description %> | ||
<%= f.text_area :description, class: "form-control" %> | ||
</div> | ||
<%= f.submit "Save", class: "btn btn-default" %> | ||
<% end %> | ||
</div> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<div class="row"> | ||
<div class="col-lg-12"> | ||
<table class="table table-hover"> | ||
<thead> | ||
<th>Ranking</th> | ||
<th>Name</th> | ||
<th>Upvote</th> | ||
</thead> | ||
<tbody> | ||
<% @albums.each do |album| %> | ||
<tr> | ||
<td>Ranked: <%= album.rank%></td> | ||
<td><%= link_to album.title, album_path(album.id) %></td> | ||
<td><%= button_to 'Upvote', upvote_album_path(album.id), class: 'btn btn-default' %></td> | ||
</tr> | ||
<% end %> | ||
</tbody> | ||
</table> | ||
<%= button_to 'View All Media', root_path, :method => :get, class: 'btn btn-default' %> <%= button_to 'Add An Ablum ', new_album_path , :method => :get, class: 'btn btn-default' %> | ||
</div> | ||
</div> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<div class="col-lg-12"> | ||
<h2>New Album</h2> | ||
<%= form_for @album do |f| %> | ||
<div class="form-group"> | ||
<%= f.label :title %> | ||
<%= f.text_field :title, class: "form-control" %> | ||
<%= f.label :artist %> | ||
<%= f.text_field :artist, class: "form-control" %> | ||
<%= f.label :description %> | ||
<%= f.text_area :description, class: "form-control" %> | ||
</div> | ||
<%= f.submit "Save", class: "btn btn-default" %> | ||
<% end %> | ||
</div> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<div class="col-lg-12"> | ||
<h1><%= @album.title %> <small>Recorded by: <%= @album.artist %></small></h1> | ||
<h4>Ranked: <%= @album.rank %></h4> | ||
<p> | ||
<%= @album.description %> | ||
</p> | ||
<%= button_to 'Upvote', upvote_album_path(@album.id), class: "btn btn-primary" %> | ||
<%= button_to "Edit #{@album.title}", edit_album_path(@album.id) , :method => :get, class: "btn btn-default" %> | ||
<%= button_to 'Delete', album_path, :method => :delete, class: "btn btn-danger" %> | ||
<%= button_to 'View All albums', albums_path, :method => :get, class: "btn btn-default" %> | ||
<%= button_to 'View All Media', root_path, :method => :get, class: "btn btn-default" %> | ||
</div> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ℹ️ Be sure to check out polymorphic paths and see if you know how you could implement them. They're perfectly suited for this project.