・ Ruby: 2.5.7 Rails: 5.2.4 ・ Vagrant: 2.2.7 -VirtualBox: 6.1 ・ OS: macOS Catalina
The following has been implemented.
・ Slim introduction ・ Introduction of Bootstrap3 ・ Introduction of Font Awesome -Login function implementation ・ Implementation of posting function -Many-to-many category function implementation ・ Multi-layer category function implementation (preparation) ・ Multi-layer category function implementation (seed) ・ [Multi-layer category function implementation (creation form)] (https://qiita.com/matsubishi5/items/4afb4a4f307023126c66)
books_controller.rb
def edit
unless @book.user == current_user
redirect_to books_path
end
@category_parent_array = Category.category_parent_array_create
end
def update
if @book.update(book_params)
book_categories = BookCategory.where(book_id: @book.id)
book_categories.destroy_all
BookCategory.maltilevel_category_create(
@book,
params[:parent_id],
params[:children_id],
params[:grandchildren_id]
)
redirect_to @book
else
@category_parent_array = Category.category_parent_array_create
render 'edit'
end
end
book_categories = BookCategory.where(book_id: @book.id)
book_categories.destroy_all
slim:books/edit.html.slim
/Postscript
.category-form
= label_tag 'Genre'
= select_tag 'parent_id', options_for_select(@category_parent_array), class: 'form-control', id: 'parent-category'
i.fas.fa-chevron-down
br
If you do not disable turbolinks
, the select box will not work asynchronously, so be sure to disable it.
Multi-layer category function implementation (I tried to make a window with Bootstrap)
Recommended Posts