リビジョン 88da1209
| app/controllers/glossary_terms_controller.rb | ||
|---|---|---|
|
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
|
||
| ... | ... | |
|
|
||
|
def create
|
||
|
term = GlossaryTerm.new(glossary_term_params)
|
||
|
term.project = @project
|
||
|
if term.save
|
||
|
redirect_to term, notice: l(:notice_successful_create)
|
||
|
end
|
||
| ... | ... | |
|
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
|
||
| ... | ... | |
|
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
|
||
| app/views/glossary_terms/index.html.erb | ||
|---|---|---|
|
<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">
|
||
| app/views/glossary_terms/new.html.erb | ||
|---|---|---|
|
<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 %>
|
||
| config/routes.rb | ||
|---|---|---|
|
# See: http://guides.rubyonrails.org/routing.html
|
||
|
|
||
|
Rails.application.routes.draw do
|
||
|
resources :glossary_terms
|
||
|
resources :projects, shallow: true do
|
||
|
resources :glossary_terms
|
||
|
end
|
||
|
resources :glossary_categories
|
||
|
end
|
||
[phase-6]changed routes under project