Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
当我装饰一个帖子然后调用方法the_url()时,会抛出以下异常:
the_url()
NoMethodError:nil 的未定义方法“主机”:NilClass
这只发生在我调用该方法、执行 rake 任务以及 rails 应用程序运行时。
请将此包含在您的任务中: 包括 Rails.application.routes.url_helpers 示例: namespace :data do desc 'Print posts url' task sample: :environment do include Rails.application.routes.url_helpers Cama::Post.all.decorate.each do |p| puts p.the_url end end end 问候!
namespace :data do desc 'Print posts url' task sample: :environment do include Rails.application.routes.url_helpers Cama::Post.all.decorate.each do |p| puts p.the_url end end end