Rails routing is unsustainable with IE

Wanting to play with jQuery, Orbited, and FasterCSV, I created a Rails chat application.

You can view the url and there is a chat window similar to IRC. You can also export the contents of the chat window by visiting the same URL but adding the extension “.csv” to the URL.

HTML version: http://host.name/channel/sweetchatroom

CSV Version: http://host.name/channel/sweetchatroom.csv

In Firefox, Safari and Chrome, it works fine. In IE, if I visit the "HTML" URL, I get a version of the CSV page. I need to manually add ".html" to the url, for example:

http://host.name/channel/sweetchatroom.html

Now my route is as follows:

map.chat '/channel/:name.:format', :controller => 'channels', :action => 'show'

I searched Google a bit and tried the following suggestions:

map.slug '/channel/:slug.:format', :controller => 'channels', :action => 'show', :defaults => {:format => 'html'}

- and -

map.slug '/channel/:slug.:format', :controller => 'channels', :action => 'show', :format => 'html'

. -, URL- , Rails params[:format] -. , , , , . ": defaults = > ..." - , Rails.

, :

respond_to do |format|
  format.csv { 
    send_data channel_to_csv(@channel),
      :type => "text/plain",
      :filename => "#{@channel.slug}.csv",
      :disposition => 'inline'
  } 
  format.html # show.html.erb
  format.xml  { render :xml => @channel }
end

:

respond_to do |format|
  format.csv { 
    send_data channel_to_csv(@channel),
      :type => "text/plain",
      :filename => "#{@channel.slug}.csv",
      :disposition => 'inline'
  } if params[:format] == 'csv' # <-- Here is the change
  format.html # show.html.erb
  format.xml  { render :xml => @channel }
end

, . , "" . ? , , .

, - . Google StackOverflow. , .

+1
1

format.html. , IE accepts (, */*), . , IE , (, URL ), Rails , .

+2

Source: https://habr.com/ru/post/1725551/


All Articles