This project is archived and is in readonly mode.

#3966 ✓resolved
mculp

responder.rb 'text' type not working as expected

Reported by mculp | February 15th, 2010 @ 04:03 PM | in 3.0.2

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

Comments and changes to this ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

People watching this ticket

Tags

Referenced by

Pages