[phase-6]changed routes under project

This commit is contained in:
Toru Takahashi 2018-05-13 07:48:03 +09:00 committed by TAKAHASHI,Toru
parent e1ee6f8f64
commit 88da1209d3
4 changed files with 18 additions and 6 deletions

View File

@ -1,9 +1,10 @@
class GlossaryTermsController < ApplicationController
before_action :find_term_from_id, only: [:show, :edit, :update, :destroy]
before_action :find_project_from_id, only: [:index, :create]
def index
@glossary_terms = GlossaryTerm.all
@glossary_terms = GlossaryTerm.where(project_id: @project.id)
end
def new
@ -12,6 +13,7 @@ class GlossaryTermsController < ApplicationController
def create
term = GlossaryTerm.new(glossary_term_params)
term.project = @project
if term.save
redirect_to term, notice: l(:notice_successful_create)
end
@ -30,8 +32,9 @@ class GlossaryTermsController < ApplicationController
end
def destroy
project = @term.project
@term.destroy
redirect_to glossary_terms_path
redirect_to project.nil? ? home_path : project_glossary_terms_path(project)
end
# Find the term whose id is the :id parameter
@ -41,6 +44,13 @@ class GlossaryTermsController < ApplicationController
render_404
end
# 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
private
def glossary_term_params

View File

@ -1,7 +1,7 @@
<h2><%=l :label_glossary_terms %></h2>
<div class="contextual">
<%= link_to l(:label_glossary_term_new), new_glossary_term_path, class: 'icon icon-add' %>
<%= link_to l(:label_glossary_term_new), new_project_glossary_term_path, class: 'icon icon-add' %>
</div>
<table class="list">

View File

@ -1,7 +1,7 @@
<h2><%=l :label_glossary_term_new %></h2>
<%= labelled_form_for :glossary_term, @term,
url: glossary_terms_path do |f| %>
url: project_glossary_terms_path do |f| %>
<%= render partial: 'glossary_terms/form', locals: {form: f} %>
<%= f.submit l(:button_create) %>
<% end %>

View File

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