Below is the typical respond_to block im using in my controller
respond_to do |format|
format.html # show.html.erb
end
I want to restrict all mime-types except html(lets say). Couldn't come up with a solution, how is this possible? This block does nothing if the request is json, this is OK but what I want is to redirect any requests that are not html.
Thanks
The format
object yielded by respond_to
has all of the usual mime types (html, js, xml, etc), and it also has a catch-all mime type any
that will handle everything else. So, in this case:
respond_to do |format|
format.html
format.any { redirect_to :foo }
end
will use default rendering for html, and will redirect for everything else. See the docs for (a tiny bit) more information: http://apidock.com/rails/ActionController/MimeResponds/respond_to
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With