-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add album model * run migration * add 404 test * rewrite tests * controllers and views * add tests * edit artists spec * add release year * fix config for bullet gem * fix bullet * song's link to album
- Loading branch information
1 parent
1aed872
commit c5e3b6b
Showing
41 changed files
with
640 additions
and
38 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
# frozen_string_literal: true | ||
|
||
module Admin | ||
class AlbumsController < ApplicationController | ||
before_action :set_album, only: %i[show edit update destroy] | ||
before_action :authenticate_user! | ||
PAGE_LIMIT = 10 | ||
|
||
# GET /albums or /albums.json | ||
def index | ||
@albums = Album.page(params[:page]). | ||
per(PAGE_LIMIT).order('id ASC') | ||
end | ||
|
||
# GET /albums/1 or /albums/1.json | ||
def show; end | ||
|
||
# GET /albums/new | ||
def new | ||
@album = Album.new | ||
end | ||
|
||
# GET /albums/1/edit | ||
def edit; end | ||
|
||
# POST /albums or /albums.json | ||
def create | ||
@album = Album.new(album_params) | ||
|
||
respond_to do |format| | ||
if @album.save | ||
format.html { redirect_to admin_albums_url, notice: 'Album was successfully created.' } | ||
format.json { render :show, status: :created, location: @album } | ||
else | ||
format.html { render :new, status: :unprocessable_entity } | ||
format.json { render json: @album.errors, status: :unprocessable_entity } | ||
end | ||
end | ||
end | ||
|
||
# PATCH/PUT /albums/1 or /albums/1.json | ||
def update | ||
respond_to do |format| | ||
if @album.update(album_params) | ||
format.html { redirect_to admin_album_url(@album), notice: 'Album was successfully updated.' } | ||
format.json { render :show, status: :ok, location: @album } | ||
else | ||
format.html { render :edit, status: :unprocessable_entity } | ||
format.json { render json: @album.errors, status: :unprocessable_entity } | ||
end | ||
end | ||
end | ||
|
||
# DELETE /albums/1 or /albums/1.json | ||
def destroy | ||
@album.destroy | ||
|
||
respond_to do |format| | ||
format.html { redirect_to admin_albums_url, notice: 'Album was successfully destroyed.' } | ||
format.json { head :no_content } | ||
end | ||
end | ||
|
||
private | ||
|
||
# Use callbacks to share common setup or constraints between actions. | ||
def set_album | ||
@album = Album.find(params[:id]) | ||
end | ||
|
||
# Only allow a list of trusted parameters through. | ||
def album_params | ||
params.require(:album).permit(:name, :artist_id, :release_year) | ||
end | ||
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,26 @@ | ||
# frozen_string_literal: true | ||
|
||
class AlbumsController < ApplicationController | ||
before_action :set_album, only: :show | ||
PAGE_LIMIT = 10 | ||
|
||
def index | ||
@albums = Album.includes([:artist]).page(params[:page]). | ||
per(PAGE_LIMIT) | ||
end | ||
|
||
def show | ||
@songs = @album.songs.includes([:artists, :genre]) | ||
end | ||
|
||
private | ||
|
||
# Use callbacks to share common setup or constraints between actions. | ||
def set_album | ||
@album = begin | ||
Album.find(params[:id]) | ||
rescue StandardError | ||
not_found | ||
end | ||
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
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,6 @@ | ||
# frozen_string_literal: true | ||
|
||
class Album < ApplicationRecord | ||
belongs_to :artist | ||
has_many :songs, dependent: :nullify | ||
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
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,12 @@ | ||
div id="#{dom_id album}" | ||
p | ||
strong Name: | ||
=< album.name | ||
|
||
div | ||
strong Artist: | ||
=< album.artist.name | ||
|
||
p | ||
strong Release Year: | ||
=< album.release_year |
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,4 @@ | ||
# frozen_string_literal: true | ||
|
||
json.extract! album, :id, :name, :artist_id, :release_year, :created_at, :updated_at | ||
json.url album_url(album, format: :json) |
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,38 @@ | ||
== render "layouts/navbar" | ||
|
||
.container-fluid | ||
.row.lyrics-site-content | ||
== render "layouts/sidebar" | ||
|
||
main.col-md-9.col-lg-10.mt-2.mb-2 | ||
h1 Editing album | ||
|
||
= form_with scope: :album, url: admin_album_path(@album), method: :patch do |form| | ||
- if @album.errors.any? | ||
div.alert.alert-danger | ||
h2 = "#{pluralize(@album.errors.count, "error")} prohibited this album from being saved:" | ||
ul | ||
- @album.errors.each do |error| | ||
li = error.full_message | ||
|
||
.mb-3 | ||
= form.label :name, class: 'form-label' | ||
= form.text_field :name, class: 'form-control' | ||
|
||
.mb-3 | ||
= form.label :artist_id, class: 'form-label' | ||
= form.select :artist_id, Artist.all.collect {|artist| [ artist.name, artist.id ] }, {}, class: 'form-control' | ||
|
||
.mb-3 | ||
= form.label :release_year, class: 'form-label' | ||
= form.number_field :release_year, class: 'form-control' | ||
|
||
div | ||
= form.submit 'Save Album', class: 'btn btn-primary' | ||
|
||
br | ||
|
||
div | ||
= link_to "Back to albums", admin_albums_path, class: 'btn btn-secondary' | ||
|
||
== render 'layouts/footer' |
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,39 @@ | ||
== render "layouts/navbar" | ||
|
||
.container-fluid | ||
.row.lyrics-site-content | ||
== render "layouts/sidebar" | ||
|
||
main.col-md-9.col-lg-10.mt-2.mb-2 | ||
- if notice | ||
p.alert.alert-success = notice | ||
|
||
h1 Albums | ||
|
||
table.table.table-bordered#albums | ||
thead.table-dark | ||
tr | ||
th[scope='col'] | ||
| # | ||
th[scope='col'] | ||
| Name | ||
th[scope='col', colspan=3] | ||
| Action | ||
tbody.table-group-divider | ||
- @albums.each do |album| | ||
tr | ||
td | ||
=< album.id | ||
td | ||
=< album.name | ||
td | ||
= link_to "Show this album", admin_album_path(album), class: 'btn btn-success' | ||
td | ||
= link_to "Edit this album", edit_admin_album_path(album), class: 'btn btn-warning' | ||
td | ||
= button_to "Delete this album", admin_album_path(album), method: :delete, class: 'btn btn-danger' | ||
|
||
= paginate @albums, theme: 'bootstrap-5' | ||
= link_to "New album", new_admin_album_path, class: 'btn btn-primary' | ||
|
||
== render 'layouts/footer' |
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,3 @@ | ||
# frozen_string_literal: true | ||
|
||
json.array! @albums, partial: 'albums/album', as: :album |
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,38 @@ | ||
== render "layouts/navbar" | ||
|
||
.container-fluid | ||
.row.lyrics-site-content | ||
== render "layouts/sidebar" | ||
|
||
main.col-md-9.col-lg-10.mt-2.mb-2 | ||
h1 New album | ||
|
||
= form_with scope: :album, url: admin_albums_path do |form| | ||
- if @album.errors.any? | ||
.alert.alert-danger | ||
h2 = "#{pluralize(@album.errors.count, "error")} prohibited this album from being saved:" | ||
ul | ||
- @album.errors.each do |error| | ||
li = error.full_message | ||
|
||
.mb-3 | ||
= form.label :name, class: 'form-label' | ||
= form.text_field :name, class: 'form-control' | ||
|
||
.mb-3 | ||
= form.label :artist_id, class: 'form-label' | ||
= form.select :artist_id, Artist.all.collect {|artist| [ artist.name, artist.id ] }, {}, class: 'form-control' | ||
|
||
.mb-3 | ||
= form.label :release_year, class: 'form-label' | ||
= form.number_field :release_year, class: 'form-control' | ||
|
||
div | ||
= form.submit 'Create Album', class: 'btn btn-primary' | ||
|
||
br | ||
|
||
div | ||
= link_to "Back to albums", admin_albums_path, class: 'btn btn-secondary' | ||
|
||
== render 'layouts/footer' |
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,20 @@ | ||
== render "layouts/navbar" | ||
|
||
.container-fluid | ||
.row.lyrics-site-content | ||
== render "layouts/sidebar" | ||
|
||
main.col-md-9.col-lg-10.mt-2.mb-2 | ||
- if notice | ||
p.alert.alert-success = notice | ||
|
||
== render @album | ||
|
||
.mb-2 | ||
=> link_to "Edit this album", edit_admin_album_path(@album), class: 'btn btn-warning' | ||
'| | ||
=< link_to "Back to albums", admin_albums_path, class: 'btn btn-secondary' | ||
|
||
= button_to "Delete this album", admin_album_path(@album), method: :delete, class: 'btn btn-danger' | ||
|
||
== render 'layouts/footer' |
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,3 @@ | ||
# frozen_string_literal: true | ||
|
||
json.partial! 'albums/album', album: @album |
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,4 +1,4 @@ | ||
# frozen_string_literal: true | ||
|
||
json.extract! song, :id, :name, :lyric, :genre_id, :created_at, :updated_at | ||
json.extract! song, :id, :name, :lyric, :genre_id, :album_id, :created_at, :updated_at | ||
json.url song_url(song, format: :json) |
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
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,22 @@ | ||
- content_for :title, 'Japanese lyrics site' | ||
|
||
== render 'layouts/navbar_for_viewer' | ||
|
||
h1 All Albums | ||
|
||
.container-fluid | ||
.row.mt-2.lyrics-site-content | ||
main.col-md-9.col-lg-10 | ||
- @albums.each do |album| | ||
.card.mb-2 | ||
.card-body | ||
p | ||
= link_to album.name, album_path(album) | ||
p | ||
= album.artist.name | ||
p | ||
= album.release_year | ||
|
||
= paginate @albums, theme: 'bootstrap-5' | ||
|
||
== render 'layouts/footer' |
Oops, something went wrong.