[phase-6]changed routing of all glossary_term to under project

This commit is contained in:
Toru Takahashi 2018-05-13 22:02:17 +09:00 committed by TAKAHASHI,Toru
parent ce868cfcf2
commit f0da393847
5 changed files with 9 additions and 10 deletions

View File

@ -1,7 +1,7 @@
class GlossaryTermsController < ApplicationController class GlossaryTermsController < ApplicationController
before_action :find_term_from_id, only: [:show, :edit, :update, :destroy] before_action :find_term_from_id, only: [:show, :edit, :update, :destroy]
before_action :find_project_from_id, only: [:index, :create] before_action :find_project_from_id
def index def index
@glossary_terms = GlossaryTerm.where(project_id: @project.id) @glossary_terms = GlossaryTerm.where(project_id: @project.id)
@ -15,7 +15,7 @@ class GlossaryTermsController < ApplicationController
term = GlossaryTerm.new(glossary_term_params) term = GlossaryTerm.new(glossary_term_params)
term.project = @project term.project = @project
if term.save if term.save
redirect_to term, notice: l(:notice_successful_create) redirect_to [@project, term], notice: l(:notice_successful_create)
end end
end end
@ -25,16 +25,15 @@ class GlossaryTermsController < ApplicationController
def update def update
@term.attributes = glossary_term_params @term.attributes = glossary_term_params
if @term.save if @term.save
redirect_to @term, notice: l(:notice_successful_update) redirect_to [@project, @term], 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)
end end
def destroy def destroy
project = @term.project
@term.destroy @term.destroy
redirect_to project.nil? ? home_path : project_glossary_terms_path(project) redirect_to project_glossary_terms_path
end end
# Find the term whose id is the :id parameter # Find the term whose id is the :id parameter

View File

@ -1,6 +1,6 @@
<h2><%=l :label_glossary_term %> #<%= @term.id %></h2> <h2><%=l :label_glossary_term %> #<%= @term.id %></h2>
<%= labelled_form_for :glossary_term, @term, url: glossary_term_path do |f| %> <%= labelled_form_for :glossary_term, @term, url: project_glossary_term_path do |f| %>
<%= render partial: 'glossary_terms/form', locals: {form: f} %> <%= render partial: 'glossary_terms/form', locals: {form: f} %>
<%= f.submit l(:button_edit) %> <%= f.submit l(:button_edit) %>
<% end %> <% end %>

View File

@ -20,7 +20,7 @@
<%= term.id %> <%= term.id %>
</td> </td>
<td class="name"> <td class="name">
<%= link_to term.name, term %> <%= link_to term.name, [@project, term] %>
</td> </td>
<td class="roles"> <td class="roles">
<%= term.category.try!(:name) %> <%= term.category.try!(:name) %>

View File

@ -1,6 +1,6 @@
<div class="contextual"> <div class="contextual">
<%= link_to l(:button_edit), edit_glossary_term_path, class: 'icon icon-edit' %> <%= link_to l(:button_edit), edit_project_glossary_term_path, class: 'icon icon-edit' %>
<%= link_to l(:button_delete), glossary_term_path, method: :delete, <%= link_to l(:button_delete), project_glossary_term_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

@ -2,7 +2,7 @@
# See: http://guides.rubyonrails.org/routing.html # See: http://guides.rubyonrails.org/routing.html
Rails.application.routes.draw do Rails.application.routes.draw do
resources :projects, shallow: true do resources :projects do
resources :glossary_terms resources :glossary_terms
end end
resources :glossary_categories resources :glossary_categories