To edit pages or tickets please login with username/password: aaf/aaf

Ticket #165 (closed enhancement: fixed)

Opened 1 year ago

Last modified 8 months ago

FerretResult#to_param should inherit from class

Reported by: aaf Assigned to: jk
Priority: minor Milestone: 0.5
Component: 0plugin Version:
Keywords: Cc:

Description

Case: Using a models' to_param method to help generate urls. (It's becoming more widespread in Rails as people look for SEO friendly urls.)

question.rb

def to_param
  "#{id}-#{body.gsub(' ','-')}"
end

questions_controller.rb

def index
  @questions = Question.find_by_contents('mark')
end

questions/index.html.erb

<% for question in @questions %>
  <%= link_to question.body, question_path(question) %>
<% end %>

Problem: We end with a link to a url that looks like: "/questions/#<!ActsAsFerret::FerretResult?...>"

We pass 'question' to the 'question_path' url helper. The helper invokes 'to_params' on 'question' which is of the class FerretResult and since to_param is defined on FerretResult, it doesn't head to the "method_missing" function that is used to invoke methods through FerretResult onto Question.

My first hack at it: Simply add the following as an instance method to FerretResult

    def to_param
      method_missing(:to_param)
    end

*Bonus Points* Some people are even writing the link generator as follows:

  <%= link_to question.body, question %>

I've got no clue how to deal with that one :)

- markmcspadden at gmail

Change History

08/25/07 12:46:40 changed by jk

  • status changed from new to assigned.
  • milestone set to 0.5.

02/02/08 21:56:36 changed by jk

  • status changed from assigned to closed.
  • resolution set to fixed.

fixed along with #194.

To edit pages or tickets please login with username/password: aaf/aaf