我一直在尝试从以下链接配置插件 - https://www.redmine.org/plugins/digest
当我尝试发送测试邮件时,我收到以下错误。 未定义的方法`长度'为true:TrueClass
这是日志文件中的错误
Looking up projects to process...
Couldn't find all EnabledModules with 'id': (all, {:conditions=>["name = 'redmine_digest'"]}) (found 0 results, but was looking for 2)
undefined method `length' for true:TrueClass
["/home/administrator/redmine3.1/apps/redmine/htdocs/plugins/redmine_digest/app/controllers/digest_controller.rb:84:in `digest_send'", "/home/administrator/redmine3.1/apps/redmine/htdocs/plugins/redmine_digest/app/controllers/digest_controller.rb:129:in `test_email'", "/home/administrator/redmine3.1/apps/redmine/htdocs/vendor/bundle/ruby/2.0.0/gems/actionpack-4.2.4/lib/action_controller/metal/implicit_render.rb:4:in `send_action'",
digest_controller.rb文件 如果Rails :: VERSION :: MAJOR< 3 要求' rdoc / markup / simple_markup' 要求&#; rdoc / markup / simple_markup / to_html' 其他 要求' rdoc' 端
class DigestController< ApplicationController的 卸
layout 'admin'
def show_readme
filename = 'README.rdoc'
f = File.dirname(__FILE__) + '/../../' + filename
input_string = File.open(f, 'rb').read
if Rails::VERSION::MAJOR >=3
h = RDoc::Markup::ToHtml.new
instructions = h.convert(input_string)
else
p = SM::SimpleMarkup.new
h = SM::ToHtml.new
instructions = p.convert(input_string, h)
end
@readme = {
:filename => filename,
:content => instructions
}
respond_to do |format|
format.html { render :template => 'settings/digest_readme.html.erb', :layout => 'admin',
:locals => { :readme => @readme }}
end
end
def digest_send(which, options={})
is_session = @request.nil? && @_request.nil?
is_session = !is_session
if not is_session
puts "setting request"
@_request = ActionDispatch::Request.new(Rails.env)
end
if is_session
raise_delivery_errors = ActionMailer::Base.raise_delivery_errors
# Force ActionMailer to raise delivery errors so we can catch it
ActionMailer::Base.raise_delivery_errors = true
end
begin
case which
when "options"
@test = DigestMailer.digests(options)
message = l(:notice_digests_sent)
when "test"
dbg "User.current: %s" % User.current
dbg "User.current.mail: %s" % User.current.mail
@test = DigestMailer.test(User.current)
message = l(:notice_digest_sent_to, User.current.mail)
when "all"
@test = DigestMailer.digests
message = l(:notice_digests_sent)
else
message "No case found for '%s'." % which
end
if @test.nil? #or @test.empty?
message += "<p>%s</p>" % "There was no resulting email."
else
message += "<p>%d %s processed.<br />%s</p>" % [
@test.length,
@test.length == 1 ? "project was" : "projects were",
@test.join("<br />")
]
end
dbg message
if is_session
flash[:notice] = message
end
rescue Exception => e
dbg e.message
dbg e.backtrace
if Rails::VERSION::MAJOR >= 3
logger.error("%s: " % e.message) unless logger.nil?
else
logger.error e.message, e.backtrace unless logger.nil?
end
flash[:error] = l(:notice_digest_error, e.message) unless session.nil?
if is_session
flash[:error] = l(:notice_digest_error, e.message)
else
puts "Exception occurred: %s" % e.message
end
end
if is_session
ActionMailer::Base.raise_delivery_errors = raise_delivery_errors
redirect_to :controller => 'settings', :action => 'plugin', :id => 'redmine_digest'
else
puts "A session was not found."
end
end
def send_digest(options={})
dbg "Preparing to send digest..."
dbg options.inspect
digest_send("options", options)
end
def send_all
dbg "Preparing to send digest for all projects."
digest_send "all"
end
def test_email
dbg "Preparing to send test digest."
digest_send "test"
end
def dbg(message)
if Setting.plugin_redmine_digest[:debugging_messages]
puts message
logger.info(message)
else
puts "debugging_messages: %s" % Setting.plugin_redmine_digest[:debugging_messages]
logger.info("debugging_messages: %s" % Setting.plugin_redmine_digest[:debugging_messages])
end
end
def self.logger
if Rails::VERSION::MAJOR >= 3
logger = Rails.logger
else
logger = RAILS_DEFAULT_LOGGER
end
return logger unless logger.nil?
#ActionController::Base::logger
end
端
答案 0 :(得分:0)
检查@test.nil?
是不够的;你还需要检查它的类型。您可以通过调用String
上的to_s
方法将其转换为@test
对象,或者您可以检查其类,它是字符串还是不符合以下内容:
if !@test.nil? && @test.is_a? String
# do your stuff
else
end