Skip to content

Commit

Permalink
rewrite form for album
Browse files Browse the repository at this point in the history
  • Loading branch information
BlazingRockStorm committed Aug 19, 2024
1 parent 0650aa4 commit 1099a08
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 51 deletions.
2 changes: 1 addition & 1 deletion app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
class ApplicationController < ActionController::Base
# rubocop:disable Naming/VariableNumber
rescue_from Exception, with: :render_500 if Rails.env.production?
rescue_from ActionController::RoutingError, with: :render_404 if Rails.env.production?
rescue_from ActionController::RoutingError, with: :render_404 if Rails.env.production?
rescue_from ActiveRecord::RecordNotFound, with: :render_404 if Rails.env.production?
# rubocop:enable Naming/VariableNumber

Expand Down
22 changes: 22 additions & 0 deletions app/views/admin/albums/_form.html.slim
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
= form_with model: [:admin, @album], local: true 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 class: 'btn btn-primary'
29 changes: 4 additions & 25 deletions app/views/admin/albums/edit.html.slim
Original file line number Diff line number Diff line change
@@ -1,38 +1,17 @@
== render "layouts/navbar"
== render 'layouts/navbar'

.container-fluid
.row.lyrics-site-content
== render "layouts/sidebar"
== 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'
== render 'form', album: @album

br

div
= link_to "Back to albums", admin_albums_path, class: 'btn btn-secondary'
= link_to 'Back to albums', admin_albums_path, class: 'btn btn-secondary'

== render 'layouts/footer'
29 changes: 4 additions & 25 deletions app/views/admin/albums/new.html.slim
Original file line number Diff line number Diff line change
@@ -1,38 +1,17 @@
== render "layouts/navbar"
== render 'layouts/navbar'

.container-fluid
.row.lyrics-site-content
== render "layouts/sidebar"
== 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'
== render 'form', album: @album

br

div
= link_to "Back to albums", admin_albums_path, class: 'btn btn-secondary'
= link_to 'Back to albums', admin_albums_path, class: 'btn btn-secondary'

== render 'layouts/footer'

0 comments on commit 1099a08

Please sign in to comment.