Как предоставить пользовательский контроллер для представления Redmine Hook
Я написал вид Redmine Hook, который добавляет поля в нижней части описания проблемы. Мое представление о хуках должно получать данные из другого контроллера, а не из контроллера проблем.
Я использовал этот код для создания моего хука:
module RedmineKnowledgebase
class Hooks < Redmine::Hook::ViewListener
def view_issues_show_description_bottom(context = {})
context[:controller].send(:render_to_string, {
:partial => " redmine_plugin_xxx/hooks/view_issues_show_
description_bottom",
:locals => context
})
end
end
end
На мой взгляд, у меня есть таблица для заполнения:
<tbody>
<% @ok_results.each do |res| %>
<tr>
<td><%= res.id %></td>
<td><%= res.key %></td>
<td><%= res.value %></td>
</tr>
<% end %>
</tbody>
По сути, моя переменная @ok_results должна быть предоставлена контроллером, который использует модель отдыха couchdb, а не контроллером проблем.
Контроллер, который должен предоставлять переменную @ok_results, выглядит следующим образом:
class RequirementsController < ApplicationController
before_action :set_requirement, only: [:show, :edit, :update, :destroy]
# GET /requirements
# GET /requirements.json
def index
#@requirements = requirement.all
#Requirement.create(:first_name => "Homer", :last_name => "Simpson")
end
# GET /requirements/1
# GET /requirements/1.json
def show
end
def ok_result
@ok_results = Requirement.ok_result.rows
end
def by_topic
@by_topic_record = Requirement.by_topic.rows
end
def by_requirement_no
@by_req_record = Requirement.by_requirement_no.rows
end
# GET /requirements/new
def new
@requirement = Requirement.new
end
# GET /requirements/1/edit
def edit
end
# POST /requirements
# POST /requirements.json
def create
@requirement = Requirement.new(requirement_params)
print requirement_params[:name]
print requirement_params[:email]
respond_to do |format|
if @requirement.save
format.html { redirect_to @requirement, notice: 'requirement was successfully created.' }
format.json { render :show, status: :created, location: @requirement }
else
format.html { render :new }
format.json { render json: @requirement.errors, status: :unprocessable_entity }
end
end
end
и моя модель кушетки db, которая связана с вышеуказанным контроллером, выглядит следующим образом:
require 'couchrest_model'
class Requirement < CouchRest::Model::Base
use_database 'raw_files'
property :requirement_no, String
property :test_case, Array
property :topic, Array
property :round_1, Array
property :ecupn, Array
property :sim_tool_pn, Array
property :details, Array
design do
view :by_topic, :map => "function(doc){if(doc.topic){emit(doc.topic,doc.details)}}"
view :by_requirement_no, :map => "function(doc){if(doc.requirement_no){emit(doc.requirement_no,doc.test_case)}}"
view :ok_result,
:map =>
"function(doc) {
if (doc['requirement_no']) {
doc.round_1.forEach(function(res, index){
if(res == 'OK')
emit(doc.requirement_no, [doc.test_case[index], doc.topic[index]]);
});
}
}"
end
timestamps!
end
Как я могу решить эту проблему?