我们正在将2.3.18
应用程序迁移到3.2.x
. 我们在运行测试时遇到一个问题,它无法使用路由助手找到路由
这是我们面临问题的断言
#test/unit/application_helper_test.rb
def test_calendar_link_to_with_named_route
. . .
calendar_link_to(31, date, {:named_route => 'edit_detailed_reservation_path', :method => :post})
. . .
end
这是该方法的定义方式ApplicationHelper
def calendar_link_to(anchor_text, date, *args)
options = args.first.is_a?(Hash) ? args.pop : {}
method = options[:method]
named_route = options[:named_route]
url_hash = { :day => date.day, :month => date.month, :year => date.year }
url = named_route ? self.send(named_route, url_hash) : url_hash
link_options = { :id => "date-#{date.year}-#{date.month}-#{date.day}" }
if date > Parameter.event_horizon
link_options[:title] = 'This date is beyond the event horizon.'
end
link_options[:method] = method if method
link_to(anchor_text, url, link_options)
end
在运行测试时,我们收到以下错误
NoMethodError: undefined method `edit_detailed_reservation_path'
为了解决此错误,我还尝试将以下行放入 application_helper.rb
include Rails.application.routes.url_helpers
我们使用下面的命令来运行测试
rake test TEST=test/unit/application_helper_test.rb
在 Rails 2 中,edit_detailed_reservation_path
在 pry session 中检查时提供绝对 URL,但在 Rails 3 中同样不起作用。
请有人指导我们可能是什么问题以及如何解决它?