[phase-6a]change routing of glossary_category to under project
This commit is contained in:
parent
f0da393847
commit
5fa6412720
@ -1,9 +1,10 @@
|
||||
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
|
||||
@ -18,15 +19,16 @@ class GlossaryCategoriesController < ApplicationController
|
||||
|
||||
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)
|
||||
@ -34,7 +36,7 @@ class GlossaryCategoriesController < ApplicationController
|
||||
|
||||
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
|
||||
@ -45,7 +47,14 @@ class GlossaryCategoriesController < ApplicationController
|
||||
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
|
||||
|
@ -1,7 +1,7 @@
|
||||
<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 %>
|
||||
|
@ -1,7 +1,7 @@
|
||||
<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">
|
||||
@ -15,7 +15,7 @@
|
||||
<% @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>
|
||||
|
@ -1,7 +1,7 @@
|
||||
<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 %>
|
||||
|
@ -1,6 +1,6 @@
|
||||
<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>
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
Rails.application.routes.draw do
|
||||
resources :projects do
|
||||
resources :glossary_terms
|
||||
resources :glossary_terms
|
||||
resources :glossary_categories
|
||||
end
|
||||
resources :glossary_categories
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user