[phase-5]add category controller and it's views
This commit is contained in:
parent
f4d4bd8423
commit
b36e22c972
56
app/controllers/glossary_categories_controller.rb
Normal file
56
app/controllers/glossary_categories_controller.rb
Normal 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
|
2
app/helpers/glossary_categories_helper.rb
Normal file
2
app/helpers/glossary_categories_helper.rb
Normal file
@ -0,0 +1,2 @@
|
||||
module GlossaryCategoriesHelper
|
||||
end
|
3
app/views/glossary_categories/_form.html.erb
Normal file
3
app/views/glossary_categories/_form.html.erb
Normal file
@ -0,0 +1,3 @@
|
||||
<div class="box">
|
||||
<p><%= form.text_field :name, size: 60, required: true %></p>
|
||||
</div>
|
7
app/views/glossary_categories/edit.html.erb
Normal file
7
app/views/glossary_categories/edit.html.erb
Normal 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 %>
|
22
app/views/glossary_categories/index.html.erb
Normal file
22
app/views/glossary_categories/index.html.erb
Normal 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>
|
7
app/views/glossary_categories/new.html.erb
Normal file
7
app/views/glossary_categories/new.html.erb
Normal 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 %>
|
11
app/views/glossary_categories/show.html.erb
Normal file
11
app/views/glossary_categories/show.html.erb
Normal 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>
|
||||
|
||||
|
@ -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"
|
@ -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: "カテゴリの作成"
|
||||
|
8
test/functional/glossary_categories_controller_test.rb
Normal file
8
test/functional/glossary_categories_controller_test.rb
Normal 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
|
Loading…
Reference in New Issue
Block a user