プロジェクト

全般

プロフィール

操作

プラグインハンズオン サンプル » 履歴 » リビジョン 6

« 前 | リビジョン 6/20 (差分) | 次 »
Haru Iida, 2011/01/22 15:40


プラグインハンズオン サンプル

create アクションのサンプル

def create
    # IssueTemplateのインスタンス作成
    @issue_template = IssueTemplate.new    
    @issue_template.project = @project
    if request.post?
      # POSTメソッドだったら値が入力されたということ。
      # formに入力された内容をIssueTemplateのインスタンスに設定。
      @issue_template.attributes = params[:issue_template]
      if @issue_template.save
        # 保存に成功した。
        # 成功したというメッセージを設定後、詳細画面。
        flash[:notice] = l(:notice_successful_create)
        redirect_to :action => "show", :id => @issue_template.id
      end
      # 保存に失敗した場合には再度入力画面が表示される。
    end
  end

init.rbのサンプル

require 'redmine'

Redmine::Plugin.register :redmine_issue_templates do
  name 'Redmine Issue Templates plugin'
  author 'Haruyuki Iida'
  description 'This is a plugin for Redmine'
  version '0.0.1'
  url 'http://example.com/path/to/plugin'
  author_url 'http://example.com/about'
  requires_redmine :version_or_higher => '1.1.0'

  # 各アクションの権限定義。ここで定義した権限が管理メニューの「ロールと権限」に表示される。
  project_module :issue_templates do
    permission :edit_issue_templates,
      {:issue_templates => [:create, :update, :destroy]}
    permission :show_issue_templates,
      {:issue_templates => [:index, :show, :load]}
  end

  # プロジェクトメニューに追加するTABの定義
  # TABのキャプション、表示位置、TABをクリックした時に呼ばれるアクションなどを定義
  # ここではissue_templates_controllerのindexを呼ぶ設定。
  menu :project_menu, :issue_templates,
    { :controller => 'issue_templates', :action => 'index' },
    :caption => "チケットテンプレート", :after => :issues

end

index.html.erb のサンプル

<h2>IssueTemplates#index</h2>

<%= link_to '新規作成', :controller => 'issue_templates',
  :action => 'create', :id=>@project %>

create.html.erb のサンプル


<h2>テンプレートの作成</h2>

<% labelled_tabular_form_for :issue_template, @issue_template, :action => 'update' do |f|%>
    <p>
      <%= f.text_field :title, :size => 50, :required => true %>
    </p>
    <p>
      <%= f.text_field :note, :size => 80, :label => l(:issue_template_note) %>
    </p>
    <p><%= f.text_area :description, :rows => 8, :cols=>60, :accesskey => accesskey(:edit), :class => 'wiki-edit' ,:required => true %></p>
    <%= submit_tag l(:button_apply) %>
  <% end %>


Updated by Haru Iida , 13年以上前に更新
Access count: 69010 :since 2009-10-30

Haru Iida さんが13年以上前に更新 · 6件の履歴