我正在为Redmine开发一个插件。我想添加一个名为Quote的模型,以及一个名为QuoteIssue的连接模型。
分贝/迁移/ 001_create_quotes.rb
<?php
$html = '<!DOCTYPE html><html><head><title>Sample</title></head><body><img src="https://example.com/images/example.jpg"></body></html>';
$doc = new DOMDocument();
$doc->loadHTML($html);
$images = $doc->getElementsByTagName('img');
foreach ($images as $image) {
$src = $image->getAttribute('src');
$noscript = $doc->createElement('noscript');
$node = $doc->createElement('div');
//$node = $doc->createElement('img'); If a uncomment this line the script just times out
$node->setAttribute('src', $src);
$noscript->appendChild($node);
$image->setAttribute('x-data-src', $src);
$image->removeAttribute('src');
$image->parentNode->appendChild($noscript);
//$image->parentNode->appendChild($newImage);
}
$body = $doc->saveHTML();
echo $body;
分贝/迁移/ 002_create_quote_issues.rb
class CreateQuotes < ActiveRecord::Migration
def change
create_table :quotes do |t|
t.references :project, foreign_key: true
t.timestamps
end
end
end
应用程序/模型/ quote.rb
class CreateQuoteIssues < ActiveRecord::Migration
def change
create_table :quote_issues do |t|
t.belongs_to :quote, index: true
t.belongs_to :issue, index: true
t.timestamps
end
end
end
应用程序/模型/ quote_issue.rb
class Quote < ActiveRecord::Base
has_one :project
has_many :quote_issues
has_many :issues, :through => :quote_issues
end
我甚至修补了问题以添加关系:
LIB / issue_patch.rb
class QuoteIssue < ActiveRecord::Base
belongs_to :quote
belongs_to :issue
end
所有事情都已成为according to the docs I read
现在即使从引用到问题的关系相当明显,rails也无法弄清楚:
require_dependency 'issue'
module IssuePatch
def self.include(base)
base.extend(ClassMethods)
base.send(:include, InstanceMethods)
base.class_eval do
has_many :quote_issues
has_many :quotes, :through => :quote_issues
end
end
module ClassMethods
end
module InstanceMethods
end
end
Issue.send(:include, IssuePatch)
问号之前没有任何建议。
是因为我没有正确地遵循rails doc,还是我需要照顾Redmine的边缘案例?
服务器/版本信息: