2013-07-16 3 views
2

내가 레드 마인에 대한 특정 문제를 해결하기 위해 필요한 플러그인,하지만 난 특히 레일에 루비와 루비에서 뉴비를 해요.레드 마인 사용자 프로젝트의 우선 순위는

내가 필요한 것.

Redmine에 일부 개발자가 있습니다. 각 개발자 (= 사용자)에 대해 (홈페이지 및 MyPage에) 누군가가 지정한이 사용자의 프로젝트 우선 순위를 표시해야합니다. 예 :

Jhon: 
--- 
1. Project1 
2. Project2 
... 
Mary: 
--- 
1. Project2 
2. Project23 
3. Project1 
... 
The solution i see is the following (assuming plugin is called UserProjectPrios).

모델. 테이블 user_project_prios을 만듭니다

  • USER_ID (FK : 사용자)
  • PROJECT_ID (FK : 프로젝트)
  • 프리 오 (int)를

모델 만들기 (단지로 시작하는 것과는 무관 보일 수 있습니다 RnR :)

class UserProjectPrio < ActiveRecord::Base 
    belongs_to :user 
    belongs_to :project 
    attr_reader :project, :prio 

    def initialize (project_id, prio) 
    @project = Project.find(project_id) 
    @prio = prio 
    end 

    def self.get_user_projects(user_id) 
    user_project_prios = [] 
    self.find_by_user_id(user_id).each do |up| 
     user_project_prios.push(self.new(up.project_id, up.prio, up.enum_issueprio_position)) 
    end 

    user_project_prios 
    end 
end 

컨트롤러. 나는 후크를 사용할 수있는 홈 페이지를 알고 있습니다. like so

class Hooks < Redmine::Hook::ViewListener 
    def view_welcome_index_left (context = {}) 
    context[:user_name] = User.current.name; 
    context[:user_project_prios] = UserProjectPrio.get_user_projects(???user_id???); 

    context[:controller].send(:render_to_string, { 
     :partial => "hooks/user_project_prios/user_project_prios", 
     :locals => context 
    }) 
    end 
end 

이제 문제는 user_id입니다. Redmine의 Class User는 공개 ID가 아닌 것으로 보입니다. 그래서 현재 유저의 UserProjectPrios 님을 어떻게 찾을 수 있습니까?

또는 내가 잘못된 방법으로 정말이야 ...?

+0

글쎄, 나는 그 사용자 ID가 잘못되어있어. 그냥 User.current.id. 그러나 중요한 질문은 남아 있습니다 : 더 나은 해결책이 있습니까? –

답변

0

그래, 간단한 방법입니다 그래서 :

class Hooks < Redmine::Hook::ViewListener 
    def view_welcome_index_left (context = {}) 
    user_project_prios = UserProjectPrio.all(:conditions => { :user_id => User.current.id }, :order => "prio ASC"); 

    context[:user_name] = User.current.name; 
    context[:user_project_prios] = user_project_prios 

    context[:controller].send(:render_to_string, { 
     :partial => "hooks/user_project_prios/user_project_prios", 
     :locals => context 
    }) 
    end 
end 

그리고 모델

class UserProjectPrio < ActiveRecord::Base 
    belongs_to :project 
end 

그리고, 단지 템플릿 user_project_prios 이상 루프 가져 오기 프로젝트와 같은

<ul> 
    <% user_project_prios.each do |upp| %> 
    <li><%= upp.project.name %></li> 
    <% end %> 
</ul> 

그러나 이제 나는 테이블에 문제가있다.

class CreateUserProjectPrios < ActiveRecord::Migration 
    def self.up 
    create_table :user_project_prios do |t| 
     t.references :user 
     t.references :project 
     t.string :prio 
     t.string :enum_issueprio_position 
    end 

    change_table :user_project_prios do |t| 
     t.index ([:user_id, :project_id, :prio, :enum_issueprio_position], :name => 'unique_key', :unique => true) 
    end 
    end 

    def self.down 
    drop_table :user_project_prios 
    end 
end 

그리고 USER_ID 결과 필드

, 아니 외래 키가 생성되지 않습니다 PROJECT_ID : 나는 다음 생성 코드를 사용합니다. 내가 놓친 게 있니?

+0

나는 같은 문제가있다. – eri