reasoncorp / dossier

Ruby-based report generation/presentation Rails engine.
MIT License
385 stars 79 forks source link

undefined method `url_helpers' #21

Closed mattslay closed 10 years ago

mattslay commented 11 years ago

I'm getting this error when running a report. It says the url_helpers method is undefined:

NoMethodError at /reports/contacts. undefined method `url_helpers' for Dossier::Formatter:Module

  def format_id(value)
     if value.is_a?(Integer)
       formatter.link_to value, formatter.url_helpers.edit_contact_path(value)
     else
       value
     end
   end
maxehmookau commented 10 years ago

:+1: Same here. When I run formatter.methods, :link_to is not in the list.

adamhunter commented 10 years ago

Hey,

link_to is stored on an object inside of the formatter, specifically: url_formatter. You should be able to access as such:

def format_id(value)
  link = formatter.url_formatter.link_to value, formatter.url_formatter.url_helpers.edit_contact_path(value)
  Integer === value ? link : value
end

Alternatively, to shorten that up, you can make your formatter for that report class include the Dossier::Formatter::UrlFormatter module

def formatter
  @formatter ||= Class.new(Dossier::Formatter::UrlFormatter) { 
    include Dossier::Formatter
  }.new 
end

def format_id(value)
  Integer === value ? formatter.link_to value, formatter.url_helpers.edit_contact_path(value) : value
end

Please let me know if you have any questions. Thanks!