Ever write this?
before_filter :csv?, :only => :index
def index
respond_to do |format|
format.html { @users = User.all }
format.csv { @users = User.to_csv }
end
end
def csv?
if request.format == :csv && ! logged_in?
log_in
end
end
This would be a lot nicer if we could get rid of that #== in #csv?
def csv?
if request.format.csv? && ! logged_in?
log_in
end
end
Introducing What
What is a plugin that automatically adds those nice query methods to ActionController::Mime::Type, the type of object returned by Request#format. All the built in mime types are supported. Any custom mime types that you add will also have corresponding query methods.