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