将自定义mimetype添加到rails格式
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了将自定义mimetype添加到rails格式相关的知识,希望对你有一定的参考价值。
#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!
以上是关于将自定义mimetype添加到rails格式的主要内容,如果未能解决你的问题,请参考以下文章
如何将自定义 RESTful 路由添加到 Rails 应用程序?
将自定义javascript添加到nested_form(Rails)