-
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.
refactor(book): Move book to Admin namespace
- Loading branch information
1 parent
7ecf24f
commit e8bebdd
Showing
13 changed files
with
98 additions
and
90 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,63 @@ | ||
# frozen_string_literal: true | ||
|
||
module Admin | ||
class BooksController < ApplicationController | ||
before_action :set_book, only: %i[show edit update destroy] | ||
|
||
def index | ||
@q = Book.ransack(params[:q]) | ||
@books = @q.result(distinct: true).includes(:author) | ||
end | ||
|
||
def show; end | ||
|
||
def new | ||
@book = Book.new | ||
end | ||
|
||
def edit; end | ||
|
||
def create | ||
@book = Book.new(book_params) | ||
|
||
if @book.save | ||
redirect_to admin_book_url(@book), notice: "Book was successfully created." | ||
else | ||
render :new, status: :unprocessable_entity | ||
end | ||
end | ||
|
||
def update | ||
if @book.update(book_params) | ||
@book.assemblies.clear | ||
|
||
assembly_ids = Array(params[:book][:assembly_ids]).select(&:present?) | ||
@book.assembly_ids = assembly_ids | ||
|
||
redirect_to admin_book_url(@book), notice: "Book was successfully updated." | ||
else | ||
render :edit, status: :unprocessable_entity | ||
end | ||
end | ||
|
||
def destroy | ||
@book.destroy | ||
|
||
redirect_to admin_books_url, notice: "Book was successfully destroyed." | ||
end | ||
|
||
def report | ||
@book = Book.includes(assemblies: :parts).find(params[:id]) | ||
end | ||
|
||
private | ||
|
||
def set_book | ||
@book = Book.find(params[:id]) | ||
end | ||
|
||
def book_params | ||
params.require(:book).permit(:title, :published_at, :isbn, :author_id, assembly_ids: []) | ||
end | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
app/views/books/_form.html.erb → app/views/admin/books/_form.html.erb
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,10 @@ | ||
<h1>Editing book</h1> | ||
|
||
<%= render "form", book: @book %> | ||
|
||
<br> | ||
|
||
<div> | ||
<%= link_to "Show this book", admin_book_path(@book) %> | | ||
<%= link_to "Back to books", admin_books_path %> | ||
</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 |
---|---|---|
|
@@ -5,5 +5,5 @@ | |
<br> | ||
|
||
<div> | ||
<%= link_to "Back to books", books_path %> | ||
<%= link_to "Back to books", admin_books_path %> | ||
</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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<p style="color: green"><%= notice %></p> | ||
|
||
<%= render "admin/books/book", book: @book %> | ||
|
||
<div> | ||
<%= link_to "Edit this book", edit_admin_book_path(@book) %> | | ||
<%= link_to "Back to books", admin_books_path %> | | ||
<%= link_to "Show report", report_admin_book_path(@book) %> | ||
<%= button_to "Destroy this book", admin_book_path(@book), method: :delete %> | ||
</div> |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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