Ruby 关于 Rails 和 redmine Aglie 插件修复

Ruby On Rails and redmine Aglie plugin fixing

好吧,你们可能知道,在 redmine 基础结构中有 tables issuesprojects。顺便说一句,我以前从来没有在 ruby 中编写代码。但是我有任务,所以。 这里的 issues table 结构: 这是 project table 结构: 问题是我也需要在 project_id equals @project and project.parent_id equals @project 中获取所有 issues。 问题是,首先我不明白当前@project 的内容。其次,我不知道如何在此处访问@project 的 parent_id 字段。 Parent_id顺便引用了project.id字段。

我在这里得到了 ruby 功能。 老板说我需要编辑范围变量。所以我试着像这样编辑它:

def find_no_version_issues
    @backlog_version = @project.versions.open.where("LOWER(#{Version.table_name}.name) LIKE LOWER(?)", "backlog").first ||
        @project.versions.open.where(:effective_date => nil).first ||
        Version.open.where(:project_id => @project).order("effective_date ASC").first

         @current_version = Version.open.
        where(:project_id => @project).
        where("#{Version.table_name}.id <> ?", @backlog_version).
        order("effective_date DEcSC").first

    q = (params[:q] || params[:term]).to_s.strip
    #scope = (params[:scope] == "all" || @project.nil? ? Issue : @project.issues).open.visible.where(:fixed_version_id => nil).sorted_by_rank
    scope = Issue.open.visible.where(:fixed_version_id => nil).where("project_id = ?", ) OR @project.or(:project_id.parent_id => @project)).sorted_by_rank
    #scope = Issue.open.visible.where(:project_id => @current_version) #(:project_id => @project || @project.parent_id == :project_id || @project ).sorted_by_rank
    if q.present?
      if q.match(/^#?(\d+)\z/)
        scope = scope.where("(#{Issue.table_name}.id = ?) OR (LOWER(#{Issue.table_name}.subject) LIKE LOWER(?))", .to_i, "%#{q}%")
      else
        scope = scope.where("LOWER(#{Issue.table_name}.subject) LIKE LOWER(?)", "%#{q}%")
      end
    end
    @issue_count = scope.count
    @issue_pages = Redmine::Pagination::Paginator.new @issue_count, 20, params['page']
    @version_issues = scope.offset(@issue_pages.offset).limit(@issue_pages.per_page).all
  end

那么,有人可以帮助我吗?我怎么能理解@project 包含什么?我怎样才能将查询变成范围?

这是有效的 SQL-查询(或者至少它有我需要的行)。但我真的不知道如何让这个 scope 变量包含这些数据?

SELECT * FROM `issues` WHERE `project_id` IN (SELECT `id` FROM `projects` WHERE `parent_id` IS NOT NULL OR `parent_id` IS NULL ) ORDER BY `id` ASC

嗯,其实我是这样修的

 def find_no_version_issues
    q = (params[:q] || params[:term]).to_s.strip
    #scope = (params[:scope] == "all" || @project.nil? ? Issue : @project.issues).open.visible.where(:fixed_version_id => nil).sorted_by_rank
    @subprojects = @project.descendants.visible.all
    @subprojects = @subprojects.to_a.push @project
    scope = Issue.open.visible.where(project_id:@subprojects).where(:fixed_version_id => nil).sorted_by_rank
    if q.present?
      if q.match(/^#?(\d+)\z/)
        scope = scope.where("(#{Issue.table_name}.id = ?) OR (LOWER(#{Issue.table_name}.subject) LIKE LOWER(?))", .to_i, "%#{q}%")
      else
        scope = scope.where("LOWER(#{Issue.table_name}.subject) LIKE LOWER(?)", "%#{q}%")
      end
    end
    @issue_count = scope.count
    @issue_pages = Redmine::Pagination::Paginator.new @issue_count, 20, params['page']
    @version_issues = scope.offset(@issue_pages.offset).limit(@issue_pages.per_page).all
  end