Skip to content

Commit

Permalink
rails 3.1/3.2 form_for
Browse files Browse the repository at this point in the history
  • Loading branch information
jlsync committed Apr 1, 2012
1 parent 8e0a60a commit 9921cd0
Showing 1 changed file with 4 additions and 10 deletions.
14 changes: 4 additions & 10 deletions lib/resources_controller/helper.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -75,16 +75,9 @@ def self.included(base)
def form_for_resource(*args, &block) def form_for_resource(*args, &block)
options = args.extract_options! options = args.extract_options!
resource = args[0] || self.resource 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 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 # print the error messages for the current resource
def error_messages_for_resource def error_messages_for_resource
error_messages_for resource_name error_messages_for resource_name
Expand All @@ -107,10 +100,11 @@ def respond_to_with_named_route_helper?(*args)
end end


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

0 comments on commit 9921cd0

Please sign in to comment.