[phase-6a]change routing of glossary_category to under project

This commit is contained in:
Toru Takahashi 2018-05-19 01:10:40 +09:00 committed by TAKAHASHI,Toru
parent f0da393847
commit 5fa6412720
6 changed files with 22 additions and 13 deletions

View File

@ -1,9 +1,10 @@
class GlossaryCategoriesController < ApplicationController class GlossaryCategoriesController < ApplicationController
before_action :find_category_from_id, only: [:show, :edit, :update, :destroy] before_action :find_category_from_id, only: [:show, :edit, :update, :destroy]
before_action :find_project_from_id
def index def index
@categories = GlossaryCategory.all @categories = GlossaryCategory.where(project_id: @project_id)
end end
def show def show
@ -18,15 +19,16 @@ class GlossaryCategoriesController < ApplicationController
def create def create
category = GlossaryCategory.new(glossary_category_params) category = GlossaryCategory.new(glossary_category_params)
category.project = @project
if category.save if category.save
redirect_to category, notice: l(:notice_successful_create) redirect_to [@project, category], notice: l(:notice_successful_create)
end end
end end
def update def update
@category.attributes = glossary_category_params @category.attributes = glossary_category_params
if @category.save if @category.save
redirect_to @category, notice: l(:notice_successful_update) redirect_to [@project, @category], notice: l(:notice_successful_update)
end end
rescue ActiveRecord::StaleObjectError rescue ActiveRecord::StaleObjectError
flash.now[:error] = l(:notice_locking_conflict) flash.now[:error] = l(:notice_locking_conflict)
@ -34,7 +36,7 @@ class GlossaryCategoriesController < ApplicationController
def destroy def destroy
@category.destroy @category.destroy
redirect_to glossary_categories_path redirect_to project_glossary_categories_path
end end
# Find the category whose id is the :id parameter # Find the category whose id is the :id parameter
@ -45,7 +47,14 @@ class GlossaryCategoriesController < ApplicationController
end end
private 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 def glossary_category_params
params.require(:glossary_category).permit( params.require(:glossary_category).permit(
:name :name

View File

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

View File

@ -1,7 +1,7 @@
<h2><%=l :label_glossary_categories %></h2> <h2><%=l :label_glossary_categories %></h2>
<div class="contextual"> <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> </div>
<table class="list"> <table class="list">
@ -15,7 +15,7 @@
<% @categories.each do |category| %> <% @categories.each do |category| %>
<tr> <tr>
<td class="id"><%= category.id %></td> <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> </tr>
<% end %> <% end %>
</tbody> </tbody>

View File

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

View File

@ -1,6 +1,6 @@
<div class="contextual"> <div class="contextual">
<%= link_to l(:button_edit), edit_glossary_category_path, class: 'icon icon-edit' %> <%= link_to l(:button_edit), edit_project_glossary_category_path, class: 'icon icon-edit' %>
<%= link_to l(:button_delete), glossary_category_path, method: :delete, <%= link_to l(:button_delete), project_glossary_category_path, method: :delete,
data: {confirm: l(:text_are_you_sure)}, class: 'icon icon-del' %> data: {confirm: l(:text_are_you_sure)}, class: 'icon icon-del' %>
</div> </div>

View File

@ -3,7 +3,7 @@
Rails.application.routes.draw do Rails.application.routes.draw do
resources :projects do resources :projects do
resources :glossary_terms resources :glossary_terms
resources :glossary_categories
end end
resources :glossary_categories
end end