Ruby on rails Redmine用户项目优先级插件
我需要为Redmine解决一个特定的问题,但我是Ruby和RubyonRails的新手 所以我需要什么 我在Redmine有一些开发人员。对于每个开发者(=用户),我需要(在主页和MyPage上)显示某人指定的该用户的项目优先级。例如。:Ruby on rails Redmine用户项目优先级插件,ruby-on-rails,redmine,redmine-plugins,Ruby On Rails,Redmine,Redmine Plugins,我需要为Redmine解决一个特定的问题,但我是Ruby和RubyonRails的新手 所以我需要什么 我在Redmine有一些开发人员。对于每个开发者(=用户),我需要(在主页和MyPage上)显示某人指定的该用户的项目优先级。例如。: 控制器。我知道在主页上我可以使用钩子。像这样 class Hooks < Redmine::Hook::ViewListener def view_welcome_index_left (context = {}) context[:use
控制器。我知道在主页上我可以使用钩子。像这样
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
类钩子“hooks/user\u project\u prios/user\u project\u prios”,
:locals=>context
})
结束
结束
现在这里的问题是用户id。Redmine中的类用户似乎不向公众公开其id。那么如何为当前用户找到UserProjectPrios
或者我真的错了…?是的,简单的方法是:
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
类钩子{:user_id=>user.current.id},:order=>“prio ASC”);
上下文[:user\u name]=user.current.name;
上下文[:用户\项目\优先级]=用户\项目\优先级
context[:controller].send(:render\u to\u字符串{
:partial=>“hooks/user\u project\u prios/user\u project\u prios”,
:locals=>context
})
结束
结束
模型呢
class UserProjectPrio < ActiveRecord::Base
belongs_to :project
end
类UserProjectPrio
然后,只需在模板中的user\u project\u 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
class CreateUserProjectPriosunique\u key',:unique=>true)
结束
结束
def自动关闭
drop\u表:用户\u项目\u优先级
结束
结束
对于结果字段user\u id、project\u id,不创建外键。我遗漏了什么吗?嗯,我错了,因为用户id是可用的。只有User.current.id。但主要问题依然存在:有更好的解决方案吗?
<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