I am trying to understand the Rails 3 responder functionality
and respond_with. However, for the built-in 'text' mime-type, it
seems a bit counter-intuitive. responder.rb seems to only check for
'to_text' in my model -- it is never called and I have to overwrite
'to_s' to get the expected results.
controller
respond_to :html, :text, :only => [:show, :random]
def show
@quote = Quote.find(params[:id])
respond_with(@quote)
end
def random
@quote = Quote.random
respond_with(@quote) do |format|
format.html { render :action => :show }
end
end
model
this will display something like <Quote:0x3692f7c>
def to_text
"blah" # no matter what's in here
end
changed model to this and works as expected
def to_text # if I remove to_text, I get "Missing template quotes/show with {:formats=>[:text]} in view path"
end
def to_s
"#{body} --#{owner}"
end