Remove .xml extension from ActiveResource request Remove .xml extension from ActiveResource request xml xml

Remove .xml extension from ActiveResource request


You can exclude the format string from paths with:

class MyModel < ActiveResource::Base  self.include_format_in_path = falseend


You probably need to override the element_path method in your model.

According to the API, the current defintion looks like this:

def element_path(id, prefix_options = {}, query_options = nil)  prefix_options, query_options = split_options(prefix_options) if query_options.nil?    "#{prefix(prefix_options)}#{collection_name}/#{id}.#{format.extension}#{query_string(query_options)}"end

Removing the .#{format.extension} part might do what you need.


You can override methods of ActiveResource::Base

Add this lib in /lib/active_resource/extend/ directory don't forget uncomment
"config.autoload_paths += %W(#{config.root}/lib)" in config/application.rb

module ActiveResource #:nodoc:  module Extend    module WithoutExtension      module ClassMethods        def element_path_with_extension(*args)          element_path_without_extension(*args).gsub(/.json|.xml/,'')        end        def new_element_path_with_extension(*args)          new_element_path_without_extension(*args).gsub(/.json|.xml/,'')        end        def collection_path_with_extension(*args)          collection_path_without_extension(*args).gsub(/.json|.xml/,'')        end      end      def self.included(base)        base.class_eval do          extend ClassMethods          class << self            alias_method_chain :element_path, :extension            alias_method_chain :new_element_path, :extension            alias_method_chain :collection_path, :extension          end        end      end      end  end  end

in model

class MyModel < ActiveResource::Base  include ActiveResource::Extend::WithoutExtensionend