2010-07-14 00:27:38 +00:00
|
|
|
require 'inherited_resources'
|
|
|
|
require 'inherited_resources/actions'
|
|
|
|
require 'inherited_resources/responder'
|
|
|
|
|
2010-07-13 00:46:17 +00:00
|
|
|
module InheritedResources
|
|
|
|
# redirect to edit_resource_url instead of resource_url
|
|
|
|
module Actions
|
2010-07-14 00:27:38 +00:00
|
|
|
|
2010-07-13 00:46:17 +00:00
|
|
|
def create(options={}, &block)
|
|
|
|
object = build_resource
|
|
|
|
|
|
|
|
if create_resource(object)
|
|
|
|
options[:location] ||= edit_resource_url rescue nil # change here
|
|
|
|
end
|
|
|
|
|
|
|
|
respond_with_dual_blocks(object, options, &block)
|
|
|
|
end
|
|
|
|
alias :create! :create
|
|
|
|
|
|
|
|
# PUT /resources/1
|
|
|
|
def update(options={}, &block)
|
|
|
|
object = resource
|
|
|
|
|
|
|
|
if update_resource(object, params[resource_instance_name])
|
|
|
|
options[:location] ||= edit_resource_url rescue nil # change here
|
|
|
|
end
|
|
|
|
|
|
|
|
respond_with_dual_blocks(object, options, &block)
|
|
|
|
end
|
|
|
|
alias :update! :update
|
2010-07-14 00:27:38 +00:00
|
|
|
|
2010-07-13 00:46:17 +00:00
|
|
|
# DELETE /resources/1
|
|
|
|
def destroy(options={}, &block)
|
|
|
|
object = resource
|
|
|
|
options[:location] ||= collection_url rescue nil
|
|
|
|
|
|
|
|
destroy_resource(object)
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2010-07-13 00:46:17 +00:00
|
|
|
options[:alert] = object.errors.full_messages.first # display the first error if present
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2010-07-13 00:46:17 +00:00
|
|
|
respond_with_dual_blocks(object, options, &block)
|
|
|
|
end
|
|
|
|
alias :destroy! :destroy
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2010-07-13 00:46:17 +00:00
|
|
|
end
|
2010-07-23 20:09:54 +00:00
|
|
|
end
|