parent/child CRUD complete
This commit is contained in:
14
app/views/children/_form.html.haml
Normal file
14
app/views/children/_form.html.haml
Normal file
@ -0,0 +1,14 @@
|
||||
- if @child.errors.full_messages.any?
|
||||
.errors
|
||||
%h1 Uh oh!
|
||||
- @child.errors.full_messages.each do |error|
|
||||
%p= error
|
||||
|
||||
= form_for @child, as: :child, url: add_child_path do |f|
|
||||
= f.label :first_name
|
||||
= f.text_field :first_name
|
||||
|
||||
= f.label :last_name
|
||||
= f.text_field :last_name
|
||||
|
||||
= f.submit
|
@ -1,3 +1,4 @@
|
||||
%ul.sub-nav
|
||||
%li= link_to 'look up', lookup_child_path
|
||||
%li= link_to 'List', list_children_path
|
||||
%li= link_to 'New', new_child_path
|
||||
|
||||
|
5
app/views/children/edit.html.haml
Normal file
5
app/views/children/edit.html.haml
Normal file
@ -0,0 +1,5 @@
|
||||
%h2 Edit #{@child.name}
|
||||
|
||||
%p= link_to 'back', child_path(@child)
|
||||
|
||||
= render partial: 'form'
|
@ -2,7 +2,11 @@
|
||||
|
||||
- @children.each do |child|
|
||||
%ul
|
||||
%li= child.name
|
||||
%li
|
||||
= link_to child.name, child_path(child)
|
||||
= link_to 'edit', edit_child_path(child)
|
||||
%ul
|
||||
- child.parents.each do |parent|
|
||||
%li #{parent.name} #{page_link(parent)}
|
||||
%li
|
||||
= link_to parent.name, parent_path(parent)
|
||||
= page_link(parent)
|
||||
|
3
app/views/children/new.html.haml
Normal file
3
app/views/children/new.html.haml
Normal file
@ -0,0 +1,3 @@
|
||||
%h2 Add a New Child
|
||||
|
||||
= render partial: 'form'
|
18
app/views/children/show.html.haml
Normal file
18
app/views/children/show.html.haml
Normal file
@ -0,0 +1,18 @@
|
||||
%h2= @child.name
|
||||
%p= link_to 'edit', edit_child_path(@child)
|
||||
|
||||
- unless @child.parents.empty?
|
||||
%p Parents:
|
||||
%ul
|
||||
- @child.parents.each do |parent|
|
||||
%li
|
||||
= link_to parent.name, parent_path(parent)
|
||||
= link_to 'remove', del_parenthood_path(parent, @child), method: :delete
|
||||
|
||||
%p Add Parent:
|
||||
= form_tag add_parent_to_child_path(@child) do
|
||||
:ruby
|
||||
select_options = options_from_collection_for_select(@parents, :id, :name)
|
||||
html_options = { include_blank: true }
|
||||
= select_tag(:parent, select_options, html_options)
|
||||
= submit_tag 'Add Parent to Child'
|
Reference in New Issue
Block a user