プロジェクト

全般

プロフィール

« | » 

リビジョン 0e0aa071

高徹 高橋 徹 さんが約6年前に追加

[phase-14]add wiki-style description and preview

差分を表示:

app/controllers/glossary_terms_controller.rb
class GlossaryTermsController < ApplicationController
before_action :find_term_from_id, only: [:show, :edit, :update, :destroy]
before_action :find_project_by_project_id, :authorize
before_action :find_project_by_project_id, :authorize, except: [:preview]
before_action :find_attachments, only: [:preview]
def index
@glossary_terms = GlossaryTerm.where(project_id: @project.id)
if not params[:index].nil?
......
@term.destroy
redirect_to project_glossary_terms_path
end
def preview
term = GlossaryTerm.find_by_id(params[:id])
if term
@attachments += term.attachments
@previewed = term
end
@text = params[:glossary_term][:description]
render partial: 'common/preview'
end
# Find the term whose id is the :id parameter
def find_term_from_id
app/views/glossary_terms/_form.html.erb
<p><%= form.text_field :datatype, size: 80 %></p>
<p><%= form.text_field :codename, size: 80 %></p>
<p><%= form.select :category_id, GlossaryCategory.pluck(:name, :id), include_blank: true %></p>
<p><%= form.text_area :description, size: "80x10", required: false %></p>
<p><%= form.text_area :description, rows: 10, class: 'wiki-edit', required: false %></p>
</div>
<div class="box">
......
</p>
</div>
<%= wikitoolbar_for 'glossary_term_description' %>
app/views/glossary_terms/edit.html.erb
<h2><%=l :label_glossary_term %> #<%= @term.id %></h2>
<%= labelled_form_for @term, url: project_glossary_term_path, html: {multipart: true} do |f| %>
<%= labelled_form_for :glossary_term, @term, url: project_glossary_term_path, html: {multipart: true, id: 'term-form'} do |f| %>
<%= render partial: 'glossary_terms/form', locals: {form: f} %>
<%= f.submit l(:button_edit) %>
<%= preview_link preview_project_glossary_term_path(@project, @term), 'term-form' %>
<% end %>
<div id="preview" class="wiki" ></div>
app/views/glossary_terms/new.html.erb
<h2><%=l :label_glossary_term_new %></h2>
<%= labelled_form_for :glossary_term, @term,
url: project_glossary_terms_path, html: {multipart: true} do |f| %>
url: project_glossary_terms_path, html: {multipart: true, id: 'term-form'} do |f| %>
<%= render partial: 'glossary_terms/form', locals: {form: f} %>
<%= f.submit l(:button_create) %>
<%= preview_link preview_project_glossary_terms_path(@project), 'term-form' %>
<% end %>
<div id="preview" class="wiki"></div>
app/views/glossary_terms/show.html.erb
</tr>
<tr>
<th><%=l :field_description %></th>
<td><%= @term.description %></td>
<td><div class="wiki"><%= textilizable @term, :description %></div></td>
</tr>
<tr>
<th><%=l :field_created_on %></th>
config/routes.rb
Rails.application.routes.draw do
resources :projects do
resources :glossary_terms
resources :glossary_terms do
member do
patch 'preview'
end
collection do
post 'preview'
end
end
resources :glossary_categories
end
end

他の形式にエクスポート: Unified diff