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