Leonid Shevtsov
Leonid Shevtsov

Reputation: 14189

Keep :format in Ruby on Rails URL helpers

Suppose I use a custom :format to implement a gadget-oriented version of my site. The general idea is that I can reuse controllers with custom, gadget-oriented views.

Is there any way to make all URL helpers called from that particular format keep the same format, without hardcoding it into all helpers?

I'd like to keep controllers untouched, and redirect_to calls from the controllers ignore the current format.

Upvotes: 1

Views: 1130

Answers (1)

Leonid Shevtsov
Leonid Shevtsov

Reputation: 14189

nevermind, found an elegant solution:

def default_url_options(options = nil)
  options ||= {}
  options[:format] = :gadget if request.format == :gadget
  options
end

Upvotes: 3

Related Questions