Return to Snippet

Revision: 52350
at October 20, 2011 19:42 by guhelouis


Initial Code
#in config/initializers/mime_types.rb, declare
Mime::Type.register "device/zzz", :zzz

......

request.format => "device/zzz"

......

respond_to do |format| 	
    format.zzz { puts "abcabcabcabcabc"}
end


===============================================================================================================

In a rails3 app (3.0.5), I've declared the following mime-type (in config/initializers/mime_types.rb):

Mime::Type.register_alias "text/html", :print
In orders_controller.rb, I've the following action:

respond_to :html

def show
  @order = Order.find(params[:id])
  respond_with @order do |format|
    format.print
  end
end
Then I currently have 2 identical views corresponding to the html and print format:

show.html.haml:

= @order.name
show.print.haml:

= @order.name
Everything works as expected with the 'html' path, ie /orders/2 renders the shows the name of the order with id == 2, but if I try /orders/2.print, I get a

undefined method 'user' for nil:NilClass
as if the @order instance variable isn't passed to the 'print' view. What am I missing? Any ideas? It should be trivial, but I'm stuck on this since a few hours!

Initial URL


Initial Description


Initial Title
Adding custom MimeTypes into rails format

Initial Tags
rails

Initial Language
Rails