본문 바로가기
카테고리 없음

bitnami Redmine4 plugin 생성하기 Polls 변경하기

by 해피비(Happy plan B) 2020. 6. 20.
반응형

 안녕하세요. 행부장입니다.
(계속 업데이트되는 문서입니다. 2020. 6.21 기준)

출처: 본인 캡처

0. Bitnami Redmine 설치 (2020-06-20 기준)
  => bitnami-redmine-4.1.1-2-windows-x64-installer.exe

1. Bitnami Redmine Stack 사용 실행
  => %redmine4InstalledDir%/use_redmine.bat 실행.
      여기서 %redmine4InstalledDir%=C:\Bitnami\redmine-4.1.1-2

2. plugin 개발 경로 이동
 cd  %redmine4InstalledDir%\apps\redmine\htdocs
 저의 경우,  C:\Bitnami\redmine-4.1.1-2\apps\redmine\htdocs>
 이하 c:\~\htdocs>로 정의

3. RAILS_ENV 환경설정
c:\~\htdocs>set RAILS_ENV=prodduction
c:\~\htdocs>echo %RAILS_ENV%

4. 신규 Plugin 생성
c:\~\htdocs>bundle exec ruby bin/rails generate redmine_plugin Polls
1) inin.rb 수정 (c:\~\htdocs\plugins\polls 위치)

Redmine::Plugin.register :polls do
  name 'Polls plugin, 투표 플로그인'
  author 'Happyland HangBuJang, 행복랜드 행부장'
  description 'This is a plugin for Redmine, 레드마인 플러그인'
  version '0.0.1'
  url 'http://sns4u.tistory.com/485'
  author_url 'http://sns4u.tistory.com'
end

5.model poll 만들기
c:\~\htdocs>bundle exec ruby bin/rails generate redmine_plugin_model polls poll

1) 001_create_polls.rb 수정 (c:\~\htdocs\plugins\polls\db\migrate 위치)

class CreatePolls < ActiveRecord::Migration[5.2]
  def self.up  #MOD 
    create_table :polls do |t|
       t.column :question, :string
	 t.column :yes, :integer, :default => 0
       t.column :no, :integer, :default => 0	 
	 
	 #START ADD day, createed_on, updated_on
	 t.column :created_on, :datetime 
      t.column :updated_on, :datetime
	 #END ADD 
    end

#
    execute("ALTER TABLE polls MODIFY created_on TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL")
   execute("ALTER TABLE polls MODIFY updated_on TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP NOT NULL")
#
  end  # End  of self.up
  
  #START ADD self.down
  def self.down
   drop_table :polls
  end
  #END ADD self.down

end

2) poll.rb 수정 (c:\~\htdocs\plugins\polls\app\models 위치)

class Poll < ActiveRecord::Base
  def vote(answer)
    increment(answer == 'yes' ? :yes : :no)
  end
end


c:\~\htdocs>bundle exec rake redmine:plugins:migrate #set RAILS_ENV=production 먼저 설정 필수
한번에 하는 경우는, 
c:\~\htdocs>bundle exec rake redmine:plugins:migrate RAILS_ENV=production


(1) 설치 혹은 설치 중 오류에 의한 plugin 삭제하고 재설치하는 방법
 ① 위 redmine:plugins:migrate 성공 시, 삭제
     c:\~\htdocs>bundle exec rake redmine:plugins:migrate NAME=polls VERSION=0
 ② 위 redmine:plugins:migrate 실패 시, 삭제
    해당 db 삭제 후, (db내, drop table polls;)
 ③ 다시 위 redmine:plugins:migrate 실행

6. controller 생성
c:\~\htdocs>bundle exec ruby bin/rails generate redmine_plugin_model polls poll
 1) polls_controller.rb 수정 (c:\~\htdocs\plugins\polls\app\controllers 위치)

class PollsController < ApplicationController
  def index
    @polls = Poll.all
  end

  def vote
    poll = Poll.find(params[:id])
    poll.vote(params[:answer])
    if poll.save
      flash[:notice] = 'Vote saved.'
    end
    redirect_to :action => 'index'
  end
end


 2) index.html.erb 수정 (c:\~\htdocs\plugins\polls\app\views\polls 위치)

<h2>Polls</h2>

<% @polls.each do |poll| %>
  <p>
  <%= poll.question %>?
  <%= link_to 'Yes', { :action => 'vote', :id => poll[:id], :answer => 'yes' }, :method => :post %> (<%= poll.yes %>) /
  <%= link_to 'No', { :action => 'vote', :id => poll[:id], :answer => 'no' }, :method => :post %> (<%= poll.no %>)
  </p>
<% end %>



99. 기타

1) db에 테스트 poll 데이터 넣기
  insert into polls (question, yes) VALUES ('test01', 1);

 

감사합니다.

반응형

댓글