プラグインハンズオン サンプル » 履歴 » バージョン 13
Haru Iida, 2011/01/22 16:25
1 | 1 | Haru Iida | h1. プラグインハンズオン サンプル |
---|---|---|---|
2 | |||
3 | 13 | Haru Iida | index.html.erbのサンプル |
4 | |||
5 | <pre> |
||
6 | <table class="list"> |
||
7 | <thead> |
||
8 | <tr> |
||
9 | <th>#</th> |
||
10 | <th><%=h l(:field_title)%></th> |
||
11 | <th><%=h l(:field_updated_on)%></th> |
||
12 | <th><%=h l(:issue_template_note)%></th> |
||
13 | </tr> |
||
14 | </thead> |
||
15 | <tbody> |
||
16 | <% @issue_templates.each do |template| %> |
||
17 | <tr class="<%= cycle('odd', 'even')%>"> |
||
18 | <td><%= template.id %></td> |
||
19 | <td><%= link_to h(template.title), :action => 'show', :id => template.id, :template_id => @template %></td> |
||
20 | <td><%= format_time(template.updated_at)%> </td> |
||
21 | <td><%=h template.note%></td> |
||
22 | </tr> |
||
23 | <% end %> |
||
24 | </tbody> |
||
25 | </table> |
||
26 | |||
27 | </pre> |
||
28 | |||
29 | 12 | Haru Iida | show アクションのサンプル |
30 | <pre> |
||
31 | def show |
||
32 | @issue_template = IssueTemplate.find(params[:template_id]) |
||
33 | end |
||
34 | </pre> |
||
35 | |||
36 | 9 | Haru Iida | モデルのサンプル |
37 | <pre> |
||
38 | class IssueTemplate < ActiveRecord::Base |
||
39 | unloadable |
||
40 | belongs_to :project |
||
41 | validates_presence_of :project_id, :title, :description |
||
42 | validates_uniqueness_of :title, :scope => :project_id |
||
43 | end |
||
44 | </pre> |
||
45 | |||
46 | 5 | Haru Iida | create アクションのサンプル |
47 | |||
48 | <pre> |
||
49 | def create |
||
50 | # IssueTemplateのインスタンス作成 |
||
51 | @issue_template = IssueTemplate.new |
||
52 | 7 | Haru Iida | @issue_template.project_id = @project.id |
53 | 5 | Haru Iida | if request.post? |
54 | # POSTメソッドだったら値が入力されたということ。 |
||
55 | # formに入力された内容をIssueTemplateのインスタンスに設定。 |
||
56 | @issue_template.attributes = params[:issue_template] |
||
57 | if @issue_template.save |
||
58 | # 保存に成功した。 |
||
59 | 6 | Haru Iida | # 成功したというメッセージを設定後、詳細画面。 |
60 | 5 | Haru Iida | flash[:notice] = l(:notice_successful_create) |
61 | 11 | Haru Iida | redirect_to :action => "show", :id => @project, :template_id => @issue_template.id |
62 | 5 | Haru Iida | end |
63 | # 保存に失敗した場合には再度入力画面が表示される。 |
||
64 | end |
||
65 | end |
||
66 | </pre> |
||
67 | |||
68 | 4 | Haru Iida | init.rbのサンプル |
69 | <pre> |
||
70 | require 'redmine' |
||
71 | |||
72 | Redmine::Plugin.register :redmine_issue_templates do |
||
73 | name 'Redmine Issue Templates plugin' |
||
74 | author 'Haruyuki Iida' |
||
75 | description 'This is a plugin for Redmine' |
||
76 | version '0.0.1' |
||
77 | url 'http://example.com/path/to/plugin' |
||
78 | author_url 'http://example.com/about' |
||
79 | requires_redmine :version_or_higher => '1.1.0' |
||
80 | |||
81 | # 各アクションの権限定義。ここで定義した権限が管理メニューの「ロールと権限」に表示される。 |
||
82 | project_module :issue_templates do |
||
83 | permission :edit_issue_templates, |
||
84 | {:issue_templates => [:create, :update, :destroy]} |
||
85 | permission :show_issue_templates, |
||
86 | {:issue_templates => [:index, :show, :load]} |
||
87 | end |
||
88 | |||
89 | # プロジェクトメニューに追加するTABの定義 |
||
90 | # TABのキャプション、表示位置、TABをクリックした時に呼ばれるアクションなどを定義 |
||
91 | # ここではissue_templates_controllerのindexを呼ぶ設定。 |
||
92 | menu :project_menu, :issue_templates, |
||
93 | { :controller => 'issue_templates', :action => 'index' }, |
||
94 | :caption => "チケットテンプレート", :after => :issues |
||
95 | |||
96 | end |
||
97 | |||
98 | </pre> |
||
99 | |||
100 | 3 | Haru Iida | index.html.erb のサンプル |
101 | |||
102 | 1 | Haru Iida | <pre> |
103 | 3 | Haru Iida | <h2>IssueTemplates#index</h2> |
104 | 1 | Haru Iida | |
105 | 3 | Haru Iida | <%= link_to '新規作成', :controller => 'issue_templates', |
106 | :action => 'create', :id=>@project %> |
||
107 | </pre> |
||
108 | 1 | Haru Iida | |
109 | create.html.erb のサンプル |
||
110 | 3 | Haru Iida | |
111 | <pre> |
||
112 | |||
113 | <h2>テンプレートの作成</h2> |
||
114 | |||
115 | 10 | Haru Iida | <%= error_messages_for 'issue_template' %> |
116 | 1 | Haru Iida | <% labelled_tabular_form_for :issue_template, @issue_template, :action => 'update' do |f|%> |
117 | <p> |
||
118 | <%= f.text_field :title, :size => 50, :required => true %> |
||
119 | </p> |
||
120 | <p> |
||
121 | <%= f.text_field :note, :size => 80, :label => l(:issue_template_note) %> |
||
122 | </p> |
||
123 | <p><%= f.text_area :description, :rows => 8, :cols=>60, :accesskey => accesskey(:edit), :class => 'wiki-edit' ,:required => true %></p> |
||
124 | <%= submit_tag l(:button_apply) %> |
||
125 | <% end %> |
||
126 | </pre> |