-
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.
Merge pull request #30 from leouofa/add-book
Adding a book model
- Loading branch information
Showing
13 changed files
with
137 additions
and
2 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,13 @@ | ||
class BooksController < MetaController | ||
def component_name | ||
'Books' | ||
end | ||
|
||
def component_class | ||
'Book'.constantize | ||
end | ||
|
||
def component_params | ||
params.require(@computer_name.to_sym).permit(:title, :writing_style_id) | ||
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,2 @@ | ||
module BooksHelper | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# == Schema Information | ||
# | ||
# Table name: books | ||
# | ||
# id :bigint not null, primary key | ||
# title :text | ||
# writing_style_id :bigint not null | ||
# created_at :datetime not null | ||
# updated_at :datetime not null | ||
# | ||
class Book < ApplicationRecord | ||
belongs_to :writing_style | ||
|
||
validates :title, presence: true | ||
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,15 @@ | ||
- if @component.errors.any? | ||
=render 'partials/form_errors' | ||
|
||
=r ux.component_segment | ||
= form_with model: @component, class: 'ui form', local: true do |form| | ||
=r ux.component_field | ||
= form.label :title | ||
= form.text_field :title, value: @component.title | ||
|
||
= r ux.component_field | ||
= form.label :writing_style_id, "Writing Style" | ||
= form.collection_select :writing_style_id, WritingStyle.all, :id, :name, { prompt: "Select a Writing Style" }, class: "ui dropdown" | ||
|
||
=r ux.component_submit_field | ||
= form.submit class: 'btn-primary' |
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,9 @@ | ||
=r ux.container | ||
=r ux.row | ||
=r ux.column width: 16 | ||
= turbo_frame_tag 'crud_frame' | ||
=r ux.component_container | ||
=r ux.component_header text: "Edit #{@component_name.singularize}" | ||
=r ux.component_return_action text: '< Back', url: send(@component_list_path) | ||
=r ux.component_divider | ||
=render 'form' |
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,31 @@ | ||
=r ux.container | ||
=r ux.row | ||
=r ux.column width: 16 | ||
= turbo_frame_tag 'crud_frame' | ||
=r ux.component_container | ||
=r ux.component_header | ||
=@component_name.pluralize | ||
=r ux.component_action text: "New #{@component_name}", url: send(@component_new_path) | ||
=r ux.component_divider | ||
|
||
=r ux.div 'text-center' | ||
= paginate @component_list | ||
|
||
=r ux.table class: 'relaxed celled striped structured' | ||
=r ux.thead | ||
=r ux.tr | ||
=r ux.th text: 'Book Name' | ||
th.center.aligned colspan="2" Actions | ||
- @component_list.each do |component| | ||
=r ux.tr | ||
=r ux.td | ||
=link_to component.title, book_path(component), class: 'item text-sm', data: {'turbo-action': 'replace'} | ||
= r ux.td 'collapsing' | ||
= link_to 'Edit', send(@component_edit_path, component), class: 'btn-list-edit' | ||
= r ux.td 'collapsing' | ||
= button_to 'Delete', send(@component_delete_path, id: component.id), method: :delete, | ||
data: { turbo_confirm: "Are you sure you want to delete this #{@component_name.downcase}?" }, | ||
class: 'btn-list-delete' | ||
|
||
=r ux.div 'text-center' | ||
= paginate @component_list |
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,9 @@ | ||
=r ux.container | ||
=r ux.row | ||
=r ux.column width: 16 | ||
= turbo_frame_tag 'crud_frame' | ||
=r ux.component_container | ||
=r ux.component_header text: "New #{@component_name.singularize}" | ||
=r ux.component_return_action text: '< Back', url: send(@component_list_path) | ||
=r ux.component_divider | ||
=render 'form' |
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,10 @@ | ||
class CreateBooks < ActiveRecord::Migration[7.2] | ||
def change | ||
create_table :books do |t| | ||
t.text :title | ||
t.references :writing_style, null: false, foreign_key: true | ||
|
||
t.timestamps | ||
end | ||
end | ||
end |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.