diff --git a/app/models/category.rb b/app/models/category.rb index 3acac979..611ed265 100644 --- a/app/models/category.rb +++ b/app/models/category.rb @@ -1,7 +1,7 @@ class Category < ApplicationRecord - + has_many :questions - belongs_to :parent_categories, class_name: 'Category', foreign_key: :parent_category_id + belongs_to :parent_category, class_name: 'Category', foreign_key: :parent_category_id has_many :child_categories, class_name: 'Category', foreign_key: :parent_category_id validates :name, presence: true diff --git a/app/views/categories/_form.html.erb b/app/views/categories/_form.html.erb deleted file mode 100644 index e86104ea..00000000 --- a/app/views/categories/_form.html.erb +++ /dev/null @@ -1,42 +0,0 @@ -<%= form_for(category) do |f| %> - <% if category.errors.any? %> -
-

<%= pluralize(category.errors.count, "error") %> prohibited this category from being saved:

- - -
- <% end %> - -
- <%= f.label :name %> - <%= f.text_field :name %> -
- -
- <%= f.label :blurb %> - <%= f.text_field :blurb %> -
- -
- <%= f.label :description %> - <%= f.text_area :description %> -
- -
- <%= f.label :external_id %> - <%= f.text_field :external_id %> -
- -
- <%= f.label :parent_category_id %> - <%= f.number_field :parent_category_id %> -
- -
- <%= f.submit %> -
-<% end %> diff --git a/app/views/categories/_form.html.haml b/app/views/categories/_form.html.haml new file mode 100644 index 00000000..75bf3c83 --- /dev/null +++ b/app/views/categories/_form.html.haml @@ -0,0 +1,26 @@ += form_for(category) do |f| + - if category.errors.any? + #error_explanation + %h2 + = pluralize(category.errors.count, "error") + prohibited this category from being saved: + %ul + - category.errors.full_messages.each do |message| + %li= message + .field + = f.label :name + = f.text_field :name + .field + = f.label :blurb + = f.text_field :blurb + .field + = f.label :description + = f.text_area :description + .field + = f.label :external_id + = f.text_field :external_id + .field + = f.label :parent_category_id + = f.number_field :parent_category_id + .actions + = f.submit diff --git a/app/views/categories/_full_path.html.haml b/app/views/categories/_full_path.html.haml new file mode 100644 index 00000000..1e8550d2 --- /dev/null +++ b/app/views/categories/_full_path.html.haml @@ -0,0 +1,3 @@ +- categories = [category] +- categories << category while (category = category.parent_category) += categories.reverse.map { |category| link_to(category.name, category) }.join('  |  ').html_safe diff --git a/app/views/categories/edit.html.erb b/app/views/categories/edit.html.erb deleted file mode 100644 index b9694172..00000000 --- a/app/views/categories/edit.html.erb +++ /dev/null @@ -1,6 +0,0 @@ -

Editing Category

- -<%= render 'form', category: @category %> - -<%= link_to 'Show', @category %> | -<%= link_to 'Back', categories_path %> diff --git a/app/views/categories/edit.html.haml b/app/views/categories/edit.html.haml new file mode 100644 index 00000000..10a16e08 --- /dev/null +++ b/app/views/categories/edit.html.haml @@ -0,0 +1,5 @@ +%h1 Editing Category += render 'form', category: @category += link_to 'Show', @category +| += link_to 'Back', categories_path diff --git a/app/views/categories/index.html.erb b/app/views/categories/index.html.erb deleted file mode 100644 index b6bb945e..00000000 --- a/app/views/categories/index.html.erb +++ /dev/null @@ -1,35 +0,0 @@ -

<%= notice %>

- -

Categories

- - - - - - - - - - - - - - - <% @categories.each do |category| %> - - - - - - - - - - - <% end %> - -
NameBlurbDescriptionExternalParent category
<%= category.name %><%= category.blurb %><%= category.description %><%= category.external_id %><%= category.parent_category_id %><%= link_to 'Show', category %><%= link_to 'Edit', edit_category_path(category) %><%= link_to 'Destroy', category, method: :delete, data: { confirm: 'Are you sure?' } %>
- -
- -<%= link_to 'New Category', new_category_path %> diff --git a/app/views/categories/index.html.haml b/app/views/categories/index.html.haml new file mode 100644 index 00000000..047f34bd --- /dev/null +++ b/app/views/categories/index.html.haml @@ -0,0 +1,24 @@ +%p#notice= notice +%h1 Categories +%table + %thead + %tr + %th Name + %th Blurb + %th Description + %th External + %th Parent category + %th{:colspan => "3"} + %tbody + - @categories.each do |category| + %tr + %td= category.name + %td= category.blurb + %td= category.description + %td= category.external_id + %td= category.parent_category_id + %td= link_to 'Show', category + %td= link_to 'Edit', edit_category_path(category) + %td= link_to 'Destroy', category, method: :delete, data: { confirm: 'Are you sure?' } +%br/ += link_to 'New Category', new_category_path diff --git a/app/views/categories/new.html.erb b/app/views/categories/new.html.erb deleted file mode 100644 index 91d5ef7d..00000000 --- a/app/views/categories/new.html.erb +++ /dev/null @@ -1,5 +0,0 @@ -

New Category

- -<%= render 'form', category: @category %> - -<%= link_to 'Back', categories_path %> diff --git a/app/views/categories/new.html.haml b/app/views/categories/new.html.haml new file mode 100644 index 00000000..6ddb7a66 --- /dev/null +++ b/app/views/categories/new.html.haml @@ -0,0 +1,3 @@ +%h1 New Category += render 'form', category: @category += link_to 'Back', categories_path diff --git a/app/views/categories/show.html.erb b/app/views/categories/show.html.erb deleted file mode 100644 index 36265135..00000000 --- a/app/views/categories/show.html.erb +++ /dev/null @@ -1,29 +0,0 @@ -

<%= notice %>

- -

- Name: - <%= @category.name %> -

- -

- Blurb: - <%= @category.blurb %> -

- -

- Description: - <%= @category.description %> -

- -

- External: - <%= @category.external_id %> -

- -

- Parent category: - <%= @category.parent_category_id %> -

- -<%= link_to 'Edit', edit_category_path(@category) %> | -<%= link_to 'Back', categories_path %> diff --git a/app/views/categories/show.html.haml b/app/views/categories/show.html.haml new file mode 100644 index 00000000..6ebea540 --- /dev/null +++ b/app/views/categories/show.html.haml @@ -0,0 +1,38 @@ +%p#notice= notice +%p + %strong Name: + = @category.name +%p + %strong Blurb: + = @category.blurb +%p + %strong Description: + = @category.description +%p + %strong External: + = @category.external_id + +%p + %strong Parent Category: +   + = render partial: 'categories/full_path', locals: {category: @category} + +- if @category.child_categories.present? + %p + %strong Child Categories: + - @category.child_categories.each do |child_category| +   + = link_to child_category.name, child_category + + +%p + %strong Questions + +- @category.questions.each do |question| + %p= link_to(question.text, question) + + + += link_to 'Edit', edit_category_path(@category) +| += link_to 'Back', categories_path diff --git a/app/views/questions/_form.html.erb b/app/views/questions/_form.html.erb deleted file mode 100644 index 136bb0c7..00000000 --- a/app/views/questions/_form.html.erb +++ /dev/null @@ -1,52 +0,0 @@ -<%= form_for(question) do |f| %> - <% if question.errors.any? %> -
-

<%= pluralize(question.errors.count, "error") %> prohibited this question from being saved:

- - -
- <% end %> - -
- <%= f.label :text %> - <%= f.text_field :text %> -
- -
- <%= f.label :option1 %> - <%= f.text_field :option1 %> -
- -
- <%= f.label :option2 %> - <%= f.text_field :option2 %> -
- -
- <%= f.label :option3 %> - <%= f.text_field :option3 %> -
- -
- <%= f.label :option4 %> - <%= f.text_field :option4 %> -
- -
- <%= f.label :option5 %> - <%= f.text_field :option5 %> -
- -
- <%= f.label :category_id %> - <%= f.number_field :category_id %> -
- -
- <%= f.submit %> -
-<% end %> diff --git a/app/views/questions/_form.html.haml b/app/views/questions/_form.html.haml new file mode 100644 index 00000000..a19db4f3 --- /dev/null +++ b/app/views/questions/_form.html.haml @@ -0,0 +1,32 @@ += form_for(question) do |f| + - if question.errors.any? + #error_explanation + %h2 + = pluralize(question.errors.count, "error") + prohibited this question from being saved: + %ul + - question.errors.full_messages.each do |message| + %li= message + .field + = f.label :text + = f.text_field :text + .field + = f.label :option1 + = f.text_field :option1 + .field + = f.label :option2 + = f.text_field :option2 + .field + = f.label :option3 + = f.text_field :option3 + .field + = f.label :option4 + = f.text_field :option4 + .field + = f.label :option5 + = f.text_field :option5 + .field + = f.label :category_id + = f.number_field :category_id + .actions + = f.submit diff --git a/app/views/questions/edit.html.erb b/app/views/questions/edit.html.erb deleted file mode 100644 index 8140146c..00000000 --- a/app/views/questions/edit.html.erb +++ /dev/null @@ -1,6 +0,0 @@ -

Editing Question

- -<%= render 'form', question: @question %> - -<%= link_to 'Show', @question %> | -<%= link_to 'Back', questions_path %> diff --git a/app/views/questions/edit.html.haml b/app/views/questions/edit.html.haml new file mode 100644 index 00000000..c5edb3ae --- /dev/null +++ b/app/views/questions/edit.html.haml @@ -0,0 +1,5 @@ +%h1 Editing Question += render 'form', question: @question += link_to 'Show', @question +| += link_to 'Back', questions_path diff --git a/app/views/questions/index.html.erb b/app/views/questions/index.html.erb deleted file mode 100644 index 31e801d7..00000000 --- a/app/views/questions/index.html.erb +++ /dev/null @@ -1,39 +0,0 @@ -

<%= notice %>

- -

Questions

- - - - - - - - - - - - - - - - - <% @questions.each do |question| %> - - - - - - - - - - - - - <% end %> - -
TextOption1Option2Option3Option4Option5Category
<%= question.text %><%= question.option1 %><%= question.option2 %><%= question.option3 %><%= question.option4 %><%= question.option5 %><%= question.category_id %><%= link_to 'Show', question %><%= link_to 'Edit', edit_question_path(question) %><%= link_to 'Destroy', question, method: :delete, data: { confirm: 'Are you sure?' } %>
- -
- -<%= link_to 'New Question', new_question_path %> diff --git a/app/views/questions/index.html.haml b/app/views/questions/index.html.haml new file mode 100644 index 00000000..2bd455b1 --- /dev/null +++ b/app/views/questions/index.html.haml @@ -0,0 +1,28 @@ +%p#notice= notice +%h1 Questions +%table + %thead + %tr + %th Text + %th Option1 + %th Option2 + %th Option3 + %th Option4 + %th Option5 + %th Category + %th{:colspan => "3"} + %tbody + - @questions.each do |question| + %tr + %td= question.text + %td= question.option1 + %td= question.option2 + %td= question.option3 + %td= question.option4 + %td= question.option5 + %td= link_to(question.category.name, question.category) + %td= link_to 'Show', question + %td= link_to 'Edit', edit_question_path(question) + %td= link_to 'Destroy', question, method: :delete, data: { confirm: 'Are you sure?' } +%br/ += link_to 'New Question', new_question_path diff --git a/app/views/questions/new.html.erb b/app/views/questions/new.html.erb deleted file mode 100644 index 2d2d9b47..00000000 --- a/app/views/questions/new.html.erb +++ /dev/null @@ -1,5 +0,0 @@ -

New Question

- -<%= render 'form', question: @question %> - -<%= link_to 'Back', questions_path %> diff --git a/app/views/questions/new.html.haml b/app/views/questions/new.html.haml new file mode 100644 index 00000000..290bccf2 --- /dev/null +++ b/app/views/questions/new.html.haml @@ -0,0 +1,3 @@ +%h1 New Question += render 'form', question: @question += link_to 'Back', questions_path diff --git a/app/views/questions/show.html.erb b/app/views/questions/show.html.erb deleted file mode 100644 index dda47d04..00000000 --- a/app/views/questions/show.html.erb +++ /dev/null @@ -1,39 +0,0 @@ -

<%= notice %>

- -

- Text: - <%= @question.text %> -

- -

- Option1: - <%= @question.option1 %> -

- -

- Option2: - <%= @question.option2 %> -

- -

- Option3: - <%= @question.option3 %> -

- -

- Option4: - <%= @question.option4 %> -

- -

- Option5: - <%= @question.option5 %> -

- -

- Category: - <%= @question.category_id %> -

- -<%= link_to 'Edit', edit_question_path(@question) %> | -<%= link_to 'Back', questions_path %> diff --git a/app/views/questions/show.html.haml b/app/views/questions/show.html.haml new file mode 100644 index 00000000..c975825d --- /dev/null +++ b/app/views/questions/show.html.haml @@ -0,0 +1,27 @@ +%p#notice= notice +%p + %strong Text: + = @question.text +%p + %strong Option1: + = @question.option1 +%p + %strong Option2: + = @question.option2 +%p + %strong Option3: + = @question.option3 +%p + %strong Option4: + = @question.option4 +%p + %strong Option5: + = @question.option5 +%p + %strong Category: +   + = render partial: 'categories/full_path', locals: {category: @question.category} + += link_to 'Edit', edit_question_path(@question) +| += link_to 'Back', questions_path