リビジョン 5fa64127
| app/controllers/glossary_categories_controller.rb | ||
|---|---|---|
|
class GlossaryCategoriesController < ApplicationController
|
||
|
|
||
|
before_action :find_category_from_id, only: [:show, :edit, :update, :destroy]
|
||
|
before_action :find_project_from_id
|
||
|
|
||
|
def index
|
||
|
@categories = GlossaryCategory.all
|
||
|
@categories = GlossaryCategory.where(project_id: @project_id)
|
||
|
end
|
||
|
|
||
|
def show
|
||
| ... | ... | |
|
|
||
|
def create
|
||
|
category = GlossaryCategory.new(glossary_category_params)
|
||
|
category.project = @project
|
||
|
if category.save
|
||
|
redirect_to category, notice: l(:notice_successful_create)
|
||
|
redirect_to [@project, category], notice: l(:notice_successful_create)
|
||
|
end
|
||
|
end
|
||
|
|
||
|
def update
|
||
|
@category.attributes = glossary_category_params
|
||
|
if @category.save
|
||
|
redirect_to @category, notice: l(:notice_successful_update)
|
||
|
redirect_to [@project, @category], notice: l(:notice_successful_update)
|
||
|
end
|
||
|
rescue ActiveRecord::StaleObjectError
|
||
|
flash.now[:error] = l(:notice_locking_conflict)
|
||
| ... | ... | |
|
|
||
|
def destroy
|
||
|
@category.destroy
|
||
|
redirect_to glossary_categories_path
|
||
|
redirect_to project_glossary_categories_path
|
||
|
end
|
||
|
|
||
|
# Find the category whose id is the :id parameter
|
||
| ... | ... | |
|
end
|
||
|
|
||
|
private
|
||
|
|
||
|
|
||
|
# Find the project whose id is the :project_id parameter
|
||
|
def find_project_from_id
|
||
|
@project = Project.find(params[:project_id])
|
||
|
rescue ActiveRecord::RecordNotFound
|
||
|
render_404
|
||
|
end
|
||
|
|
||
|
def glossary_category_params
|
||
|
params.require(:glossary_category).permit(
|
||
|
:name
|
||
| app/views/glossary_categories/edit.html.erb | ||
|---|---|---|
|
<h2><%=l :label_glossary_category %> $<%= @category.id %></h2>
|
||
|
|
||
|
<%= labelled_form_for :glossary_category, @category,
|
||
|
url: glossary_category_path do |f| %>
|
||
|
url: project_glossary_category_path do |f| %>
|
||
|
<%= render partial: 'glossary_categories/form', locals: {form: f} %>
|
||
|
<%= f.submit l(:button_edit) %>
|
||
|
<% end %>
|
||
| app/views/glossary_categories/index.html.erb | ||
|---|---|---|
|
<h2><%=l :label_glossary_categories %></h2>
|
||
|
|
||
|
<div class="contextual">
|
||
|
<%= link_to l(:label_glossary_category_new), new_glossary_category_path, class: 'icon icon-add' %>
|
||
|
<%= link_to l(:label_glossary_category_new), new_project_glossary_category_path, class: 'icon icon-add' %>
|
||
|
</div>
|
||
|
|
||
|
<table class="list">
|
||
| ... | ... | |
|
<% @categories.each do |category| %>
|
||
|
<tr>
|
||
|
<td class="id"><%= category.id %></td>
|
||
|
<td class="name"><%= link_to category.name, category %></td>
|
||
|
<td class="name"><%= link_to category.name, [@project, category] %></td>
|
||
|
</tr>
|
||
|
<% end %>
|
||
|
</tbody>
|
||
| app/views/glossary_categories/new.html.erb | ||
|---|---|---|
|
<h2><%=l :label_glossary_category_new %></h2>
|
||
|
|
||
|
<%= labelled_form_for :glossary_category, @category,
|
||
|
url: glossary_categories_path do |f| %>
|
||
|
url: project_glossary_categories_path do |f| %>
|
||
|
<%= render partial: 'glossary_categories/form', locals: {form: f} %>
|
||
|
<%= f.submit l(:button_create) %>
|
||
|
<% end %>
|
||
| app/views/glossary_categories/show.html.erb | ||
|---|---|---|
|
<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,
|
||
|
<%= link_to l(:button_edit), edit_project_glossary_category_path, class: 'icon icon-edit' %>
|
||
|
<%= link_to l(:button_delete), project_glossary_category_path, method: :delete,
|
||
|
data: {confirm: l(:text_are_you_sure)}, class: 'icon icon-del' %>
|
||
|
</div>
|
||
|
|
||
| config/routes.rb | ||
|---|---|---|
|
|
||
|
Rails.application.routes.draw do
|
||
|
resources :projects do
|
||
|
resources :glossary_terms
|
||
|
resources :glossary_terms
|
||
|
resources :glossary_categories
|
||
|
end
|
||
|
resources :glossary_categories
|
||
|
end
|
||
[phase-6a]change routing of glossary_category to under project