working on questions and categories

pull/1/head
Jared Cosulich 9 years ago
parent 4bad7d013c
commit d731049fc6

@ -1,7 +1,7 @@
class Category < ApplicationRecord class Category < ApplicationRecord
has_many :questions 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 has_many :child_categories, class_name: 'Category', foreign_key: :parent_category_id
validates :name, presence: true validates :name, presence: true

@ -1,42 +0,0 @@
<%= form_for(category) do |f| %>
<% if category.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(category.errors.count, "error") %> prohibited this category from being saved:</h2>
<ul>
<% category.errors.full_messages.each do |message| %>
<li><%= message %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= f.label :name %>
<%= f.text_field :name %>
</div>
<div class="field">
<%= f.label :blurb %>
<%= f.text_field :blurb %>
</div>
<div class="field">
<%= f.label :description %>
<%= f.text_area :description %>
</div>
<div class="field">
<%= f.label :external_id %>
<%= f.text_field :external_id %>
</div>
<div class="field">
<%= f.label :parent_category_id %>
<%= f.number_field :parent_category_id %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>

@ -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

@ -0,0 +1,3 @@
- categories = [category]
- categories << category while (category = category.parent_category)
= categories.reverse.map { |category| link_to(category.name, category) }.join('&nbsp; | &nbsp;').html_safe

@ -1,6 +0,0 @@
<h1>Editing Category</h1>
<%= render 'form', category: @category %>
<%= link_to 'Show', @category %> |
<%= link_to 'Back', categories_path %>

@ -0,0 +1,5 @@
%h1 Editing Category
= render 'form', category: @category
= link_to 'Show', @category
|
= link_to 'Back', categories_path

@ -1,35 +0,0 @@
<p id="notice"><%= notice %></p>
<h1>Categories</h1>
<table>
<thead>
<tr>
<th>Name</th>
<th>Blurb</th>
<th>Description</th>
<th>External</th>
<th>Parent category</th>
<th colspan="3"></th>
</tr>
</thead>
<tbody>
<% @categories.each do |category| %>
<tr>
<td><%= category.name %></td>
<td><%= category.blurb %></td>
<td><%= category.description %></td>
<td><%= category.external_id %></td>
<td><%= category.parent_category_id %></td>
<td><%= link_to 'Show', category %></td>
<td><%= link_to 'Edit', edit_category_path(category) %></td>
<td><%= link_to 'Destroy', category, method: :delete, data: { confirm: 'Are you sure?' } %></td>
</tr>
<% end %>
</tbody>
</table>
<br>
<%= link_to 'New Category', new_category_path %>

@ -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

@ -1,5 +0,0 @@
<h1>New Category</h1>
<%= render 'form', category: @category %>
<%= link_to 'Back', categories_path %>

@ -0,0 +1,3 @@
%h1 New Category
= render 'form', category: @category
= link_to 'Back', categories_path

@ -1,29 +0,0 @@
<p id="notice"><%= notice %></p>
<p>
<strong>Name:</strong>
<%= @category.name %>
</p>
<p>
<strong>Blurb:</strong>
<%= @category.blurb %>
</p>
<p>
<strong>Description:</strong>
<%= @category.description %>
</p>
<p>
<strong>External:</strong>
<%= @category.external_id %>
</p>
<p>
<strong>Parent category:</strong>
<%= @category.parent_category_id %>
</p>
<%= link_to 'Edit', edit_category_path(@category) %> |
<%= link_to 'Back', categories_path %>

@ -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:
&nbsp;
= render partial: 'categories/full_path', locals: {category: @category}
- if @category.child_categories.present?
%p
%strong Child Categories:
- @category.child_categories.each do |child_category|
&nbsp;
= 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

@ -1,52 +0,0 @@
<%= form_for(question) do |f| %>
<% if question.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(question.errors.count, "error") %> prohibited this question from being saved:</h2>
<ul>
<% question.errors.full_messages.each do |message| %>
<li><%= message %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= f.label :text %>
<%= f.text_field :text %>
</div>
<div class="field">
<%= f.label :option1 %>
<%= f.text_field :option1 %>
</div>
<div class="field">
<%= f.label :option2 %>
<%= f.text_field :option2 %>
</div>
<div class="field">
<%= f.label :option3 %>
<%= f.text_field :option3 %>
</div>
<div class="field">
<%= f.label :option4 %>
<%= f.text_field :option4 %>
</div>
<div class="field">
<%= f.label :option5 %>
<%= f.text_field :option5 %>
</div>
<div class="field">
<%= f.label :category_id %>
<%= f.number_field :category_id %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>

@ -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

@ -1,6 +0,0 @@
<h1>Editing Question</h1>
<%= render 'form', question: @question %>
<%= link_to 'Show', @question %> |
<%= link_to 'Back', questions_path %>

@ -0,0 +1,5 @@
%h1 Editing Question
= render 'form', question: @question
= link_to 'Show', @question
|
= link_to 'Back', questions_path

@ -1,39 +0,0 @@
<p id="notice"><%= notice %></p>
<h1>Questions</h1>
<table>
<thead>
<tr>
<th>Text</th>
<th>Option1</th>
<th>Option2</th>
<th>Option3</th>
<th>Option4</th>
<th>Option5</th>
<th>Category</th>
<th colspan="3"></th>
</tr>
</thead>
<tbody>
<% @questions.each do |question| %>
<tr>
<td><%= question.text %></td>
<td><%= question.option1 %></td>
<td><%= question.option2 %></td>
<td><%= question.option3 %></td>
<td><%= question.option4 %></td>
<td><%= question.option5 %></td>
<td><%= question.category_id %></td>
<td><%= link_to 'Show', question %></td>
<td><%= link_to 'Edit', edit_question_path(question) %></td>
<td><%= link_to 'Destroy', question, method: :delete, data: { confirm: 'Are you sure?' } %></td>
</tr>
<% end %>
</tbody>
</table>
<br>
<%= link_to 'New Question', new_question_path %>

@ -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

@ -1,5 +0,0 @@
<h1>New Question</h1>
<%= render 'form', question: @question %>
<%= link_to 'Back', questions_path %>

@ -0,0 +1,3 @@
%h1 New Question
= render 'form', question: @question
= link_to 'Back', questions_path

@ -1,39 +0,0 @@
<p id="notice"><%= notice %></p>
<p>
<strong>Text:</strong>
<%= @question.text %>
</p>
<p>
<strong>Option1:</strong>
<%= @question.option1 %>
</p>
<p>
<strong>Option2:</strong>
<%= @question.option2 %>
</p>
<p>
<strong>Option3:</strong>
<%= @question.option3 %>
</p>
<p>
<strong>Option4:</strong>
<%= @question.option4 %>
</p>
<p>
<strong>Option5:</strong>
<%= @question.option5 %>
</p>
<p>
<strong>Category:</strong>
<%= @question.category_id %>
</p>
<%= link_to 'Edit', edit_question_path(@question) %> |
<%= link_to 'Back', questions_path %>

@ -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:
&nbsp;
= render partial: 'categories/full_path', locals: {category: @question.category}
= link_to 'Edit', edit_question_path(@question)
|
= link_to 'Back', questions_path
Loading…
Cancel
Save