[phase-5]add category controller and it's views

This commit is contained in:
Toru Takahashi 2018-05-06 17:17:59 +09:00 committed by TAKAHASHI,Toru
parent f4d4bd8423
commit b36e22c972
10 changed files with 124 additions and 2 deletions

View File

@ -0,0 +1,56 @@
class GlossaryCategoriesController < ApplicationController
before_action :find_category_from_id, only: [:show, :edit, :update, :destroy]
def index
@categories = GlossaryCategory.all
end
def show
end
def new
@category = GlossaryCategory.new
end
def edit
end
def create
category = GlossaryCategory.new(glossary_category_params)
if category.save
flash[:notice] = l(:notice_successful_create)
redirect_to category
end
end
def update
@category.attributes = glossary_category_params
if @category.save
flash[:notice] = l(:notice_successful_update)
redirect_to @category
end
rescue ActiveRecord::StaleObjectError
flash.now[:error] = l(:notice_locking_conflict)
end
def destroy
@category.destroy
redirect_to glossary_categories_path
end
# Find the category whose id is the :id parameter
def find_category_from_id
@category = GlossaryCategory.find(params[:id])
rescue ActiveRecord::RecordNotFound
render_404
end
private
def glossary_category_params
params.require(:glossary_category).permit(
:name
)
end
end

View File

@ -0,0 +1,2 @@
module GlossaryCategoriesHelper
end

View File

@ -0,0 +1,3 @@
<div class="box">
<p><%= form.text_field :name, size: 60, required: true %></p>
</div>

View File

@ -0,0 +1,7 @@
<h2><%=l :label_glossary_category %> $<%= @category.id %></h2>
<%= labelled_form_for :glossary_category, @category,
url: glossary_category_path do |f| %>
<%= render partial: 'glossary_categories/form', locals: {form: f} %>
<%= f.submit l(:button_edit) %>
<% end %>

View File

@ -0,0 +1,22 @@
<h2><%=l :label_glossary_categories %></h2>
<div class="contextual">
<%= link_to l(:label_glossary_category_new), new_glossary_category_path, class: 'icon icon-add' %>
</div>
<table class="list">
<thead>
<tr>
<th>#</th>
<th><%=l :field_name %></th>
</tr>
</thead>
<tbody>
<% @categories.each do |category| %>
<tr>
<td class="id"><%= category.id %></td>
<td class="name"><%= link_to category.name, category %></td>
</tr>
<% end %>
</tbody>
</table>

View File

@ -0,0 +1,7 @@
<h2><%=l :label_glossary_category_new %></h2>
<%= labelled_form_for :glossary_category, @category,
url: glossary_categories_path do |f| %>
<%= render partial: 'glossary_categories/form', locals: {form: f} %>
<%= f.submit l(:button_create) %>
<% end %>

View File

@ -0,0 +1,11 @@
<div class="contextual">
<%= link_to l(:button_edit), edit_glossary_category_path, class: 'icon icon-edit' %>
<%= link_to l(:button_delete), glossary_category_path, method: :delete,
data: {confirm: l(:text_are_you_sure)}, class: 'icon icon-del' %>
</div>
<h2><%=l :label_glossary_category %> #<%=@category.id %></h2>
<h3><%= @category.name %></h3>

View File

@ -2,4 +2,7 @@
en:
label_glossary_terms: "Glossary terms"
label_glossary_term: "Glossary term"
label_glossary_term_new: "New glossary term"
label_glossary_term_new: "New glossary term"
label_glossary_categories: "Glossary categories"
label_glossary_category: "Glossary category"
label_glossary_category_new: "New glossary category"

View File

@ -1,4 +1,7 @@
ja:
label_glossary_terms: "用語集"
label_glossary_term: "用語"
label_glossary_term_new: "用語の作成"
label_glossary_term_new: "用語の作成"
label_glossary_categories: "用語のカテゴリ"
label_glossary_category: "用語のカテゴリ"
label_glossary_category_new: "カテゴリの作成"

View File

@ -0,0 +1,8 @@
require File.expand_path('../../test_helper', __FILE__)
class GlossaryCategoriesControllerTest < ActionController::TestCase
# Replace this with your real tests.
def test_truth
assert true
end
end