1

When I decorate a post and then call the method the_url(), the following exception is thrown:

NoMethodError: undefined method `host' for nil:NilClass

This only happens when I call the method, while performing a rake task, and when the rails app is running.

Cjmarkham
  • 9,484
  • 5
  • 48
  • 81
jpac
  • 69
  • 5

1 Answers1

2

Please include this in your task:
include Rails.application.routes.url_helpers
Sample: 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 Regards!