Permalink
Browse files

rails 3.1/3.2 form_for

  • Loading branch information...
jlsync committed Apr 1, 2012
1 parent 8e0a60a commit 9921cd028c821b1250298c384afc52a4db8d3e35
Showing with 4 additions and 10 deletions.
  1. +4 −10 lib/resources_controller/helper.rb
@@ -75,16 +75,9 @@ def self.included(base)
def form_for_resource(*args, &block)
options = args.extract_options!
resource = args[0] || self.resource
form_for(resource_name, resource, form_for_resource_options(resource, options), &block)
form_for(resource, form_for_resource_options(resource, resource_name, options), &block)
end

# same API as form_for_resource
def remote_form_for_resource(*args, &block)
options = args.extract_options!
resource = args[0] || self.resource
remote_form_for(resource_name, resource, form_for_resource_options(resource, options), &block)
end

# print the error messages for the current resource
def error_messages_for_resource
error_messages_for resource_name
@@ -107,10 +100,11 @@ def respond_to_with_named_route_helper?(*args)
end

private
def form_for_resource_options(resource, options)
def form_for_resource_options(resource, resource_name, options)
options.dup.tap do |options|
options[:html] ||= {}
options[:html][:method] ||= resource.new_record? ? :post : :put
options[:as] = resource_name
args = options[:url_options] ? [options.delete(:url_options)] : []
options[:url] ||= if resource.new_record?
controller.resource_specification.singleton? ? resource_path(*args) : resources_path(*args)
@@ -120,4 +114,4 @@ def form_for_resource_options(resource, options)
end
end
end
end
end

0 comments on commit 9921cd0

Please sign in to comment.