View with custom mime-type doesn't receive instance variable
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 co开发者_如何学JAVArresponding 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!
Ok, sorry for that, I had a before_filter method that was hiccuping on the custom mime-type. Everything is working now (I'm still learning to thoroughly read the log in case of errors).
精彩评论