在我的Redmine插件

时间:2016-06-18 17:11:37

标签: ruby-on-rails ruby android-activity plugins redmine

我目前正在开发一个redmine插件,我想让活动流中显示插件的动作,我也希望能够在我的插件创建的对象中进行搜索。 我非常仔细地遵循了Alex Bevilacque的教程。如果你对我做错了什么有任何线索,那就太好了!

一切都是关于“prestations”。

我有这个迁移我的数据库:

class CreatePrestations < ActiveRecord::Migration
  def change
    create_table :prestations do |t|
      t.column :nom, :string, :null => false
      t.column :description, :text
      t.column :project_id, :int, :default => 0
      t.column :author_id, :int, :default => 0, :null => false
      t.timestamps
    end
  end
end

这个模型:

class Prestation < ActiveRecord::Base
  belongs_to :project
  validates_presence_of :nom

  acts_as_searchable :columns => [ "#{table_name}.nom", "#{table_name}.description"],
                     :scope => preload(:project),
                     :date_column => "created_at"

  acts_as_event :title => Proc.new { |o| "#{l(:label_title_prestation)} ##{o.id} - #{o.nom}"},
                :description => :description,
                :datetime => :updated_at,
                :type => Proc.new { |o| 'prestation-' + (o.new_status ? 'add' : 'edit') },
                :url => Proc.new { |o| {:controller => 'prestations', :action => 'show', :id => o.id, :project_id => o.project} }

  acts_as_activity_provider :scope => preload(:project),
                            :author_key => :author_id,
                            :type => 'prestations',
                            :timestamp => :updated_at,
                            :permission => :activity_presta

end

这是在我的init.rb的最开头:

Rails.configuration.to_prepare do
  Redmine::Activity.register :prestations
  Redmine::Search.available_search_types << 'prestations'
end

当我点击“搜索”时,我可以搜索每个正常的红色字段,但不能搜索我的“prestations”,当我查看活动流时,我得到了这个:

ActiveRecord::StatementInvalid (SQLite3::SQLException: no such column: projects.id: SELECT "prestations".* FROM "prestations" WHERE (updated_at BETWEEN '2016-05-20' AND '2016-06-19') AND (((projects.id = 1 OR (projects.lft > 1 AND projects.rgt < 2))) AND (projects.status = 1))):
  lib/plugins/acts_as_activity_provider/lib/acts_as_activity_provider.rb:81:in `find_events'
  lib/redmine/activity/fetcher.rb:91:in `block (2 levels) in events'
  lib/redmine/activity/fetcher.rb:90:in `each'
  lib/redmine/activity/fetcher.rb:90:in `block in events'
  lib/redmine/activity/fetcher.rb:89:in `each'
  lib/redmine/activity/fetcher.rb:89:in `events'
  app/controllers/activities_controller.rb:56:in `index'
  lib/redmine/sudo_mode.rb:63:in `sudo_mode'

我重新安装数据库以从头开始新的redmine,我重新加载服务器并更改了令牌,但无济于事。

我真的不明白为什么 1)我甚至无法在我的“prestations”中搜索(只需要复选框就可以了) 2)Rails试图寻找我没有要求的“projects.id”

提前多多感谢。

1 个答案:

答案 0 :(得分:0)

我在projects.rb中找到了一些东西:

  def project_condition(with_subprojects)
    cond = "#{Project.table_name}.id = #{id}"
    cond = "(#{cond} OR (#{Project.table_name}.lft > #{lft} AND #{Project.table_name}.rgt < #{rgt}))" if with_subprojects
    cond
  end

我认为尽管Redmine Knownledgebase教程是一个很好的介绍,如果你想制作自己的插件,它真的很多。