{"action":"created","issue":{"url":"https://api.github.com/repos/rails/rails/issues/16358","labels_url":"https://api.github.com/repos/rails/rails/issues/16358/labels{/name}","comments_url":"https://api.github.com/repos/rails/rails/issues/16358/comments","events_url":"https://api.github.com/repos/rails/rails/issues/16358/events","html_url":"https://github.com/rails/rails/issues/16358","id":39180596,"number":16358,"title":"Can't set format in default_url_options","user":{"login":"nashbridges","id":380913,"avatar_url":"https://avatars.githubusercontent.com/u/380913?v=3","gravatar_id":"","url":"https://api.github.com/users/nashbridges","html_url":"https://github.com/nashbridges","followers_url":"https://api.github.com/users/nashbridges/followers","following_url":"https://api.github.com/users/nashbridges/following{/other_user}","gists_url":"https://api.github.com/users/nashbridges/gists{/gist_id}","starred_url":"https://api.github.com/users/nashbridges/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nashbridges/subscriptions","organizations_url":"https://api.github.com/users/nashbridges/orgs","repos_url":"https://api.github.com/users/nashbridges/repos","events_url":"https://api.github.com/users/nashbridges/events{/privacy}","received_events_url":"https://api.github.com/users/nashbridges/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/rails/rails/labels/actionpack","name":"actionpack","color":"FFF700"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2014-07-31T10:11:53Z","updated_at":"2015-01-28T16:53:17Z","closed_at":null,"body":"We use the old way to deliver mobile-specific content via `:format`, that is, we have `template.html.slim` and `template.mobile.slim`. We also want to persist format in URL, so a mobile user will see an `/items/10.mobile` URL instead of `/items/10`.\r\n\r\nIn Rails 3.X we could achieve this by overriding `default_url_options`, however, this is no longer work (see test example below).\r\n\r\nI've tracked the problem down to https://github.com/rails/rails/blob/master/actionpack/lib/action_dispatch/routing/route_set.rb#L260. If I extract `:format` from `@segment_keys`, then `url_for` won't receive a hash, which would otherwise include `format: nil`.\r\n\r\n```ruby\r\n#gem 'rails', '3.2.18' # OK\r\ngem 'rails', '4.0.8' # FAIL\r\n#gem 'rails', '4.1.4' # FAIL\r\n\r\n# FAIL\r\n#unless File.exist?('Gemfile')\r\n  #File.write('Gemfile', <<-GEMFILE)\r\n    #source 'https://rubygems.org'\r\n    #gem 'rails', github: 'rails/rails'\r\n    #gem 'arel', github: 'rails/arel'\r\n    #gem 'rack', github: 'rack/rack'\r\n    #gem 'i18n', github: 'svenfuchs/i18n'\r\n  #GEMFILE\r\n\r\n  #system 'bundle'\r\n#end\r\n\r\n#require 'bundler'\r\n#Bundler.setup(:default)\r\n\r\nrequire 'rails'\r\nrequire 'action_controller/railtie'\r\n\r\nclass TestApp < Rails::Application\r\n  config.root = File.dirname(__FILE__)\r\n  config.session_store :cookie_store, key: 'cookie_store_key'\r\n  config.secret_token    = 'secret_token' * 30\r\n  config.secret_key_base = 'secret_key_base'\r\n\r\n  config.logger = Logger.new($stdout)\r\n  Rails.logger  = config.logger\r\n\r\n  routes.draw do\r\n    get '/' => 'test#index'\r\n    resources :cars\r\n  end\r\nend\r\n\r\nCar = Struct.new(:to_param)\r\n\r\nclass TestController < ActionController::Base\r\n  include Rails.application.routes.url_helpers\r\n\r\n  def default_url_options(options = {})\r\n    options[:format] = params[:format] if params[:format].present?\r\n    options\r\n  end\r\n\r\n  def index\r\n    render inline: <<-VIEW\r\n      <%= link_to \"hello\", car_path(Car.new(3)) %>\r\n    VIEW\r\n  end\r\nend\r\n\r\nrequire 'minitest/autorun'\r\nrequire 'rack/test'\r\n\r\n# Ensure backward compatibility with Minitest 4\r\nMinitest::Test = MiniTest::Unit::TestCase unless defined?(Minitest::Test)\r\n\r\nclass BugTest < Minitest::Test\r\n  include Rack::Test::Methods\r\n\r\n  def test_persists_format\r\n    get '/', format: \"mobile\"\r\n    assert_equal '<a href=\"/cars/3.mobile\">hello</a>', last_response.body.strip\r\n  end\r\n\r\n  private\r\n    def app\r\n      Rails.application\r\n    end\r\nend\r\n\r\n```\r\n"},"comment":{"url":"https://api.github.com/repos/rails/rails/issues/comments/71870481","html_url":"https://github.com/rails/rails/issues/16358#issuecomment-71870481","issue_url":"https://api.github.com/repos/rails/rails/issues/16358","id":71870481,"user":{"login":"pixeltrix","id":6321,"avatar_url":"https://avatars.githubusercontent.com/u/6321?v=3","gravatar_id":"","url":"https://api.github.com/users/pixeltrix","html_url":"https://github.com/pixeltrix","followers_url":"https://api.github.com/users/pixeltrix/followers","following_url":"https://api.github.com/users/pixeltrix/following{/other_user}","gists_url":"https://api.github.com/users/pixeltrix/gists{/gist_id}","starred_url":"https://api.github.com/users/pixeltrix/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pixeltrix/subscriptions","organizations_url":"https://api.github.com/users/pixeltrix/orgs","repos_url":"https://api.github.com/users/pixeltrix/repos","events_url":"https://api.github.com/users/pixeltrix/events{/privacy}","received_events_url":"https://api.github.com/users/pixeltrix/received_events","type":"User","site_admin":false},"created_at":"2015-01-28T16:53:17Z","updated_at":"2015-01-28T16:53:17Z","body":"This maybe related to #18627"}}