Skip to content

Commit

Permalink
[#491 state:resolved] pass a correctly inflected association name to …
Browse files Browse the repository at this point in the history
…create_response in hobo_create_for
  • Loading branch information
al2o3cr committed Nov 26, 2009
1 parent a2189b1 commit 2ce25a7
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions hobo/lib/hobo/model_controller.rb
Expand Up @@ -259,7 +259,7 @@ def do_transition_action(name, options={}, &block)

def auto_actions_for(owner, actions)
name = model.reflections[owner].macro == :has_many ? owner.to_s.singularize : owner

owner_actions[owner] ||= []
Array(actions).each do |action|
case action
Expand Down Expand Up @@ -461,14 +461,17 @@ def find_or_paginate(finder, options)


def find_owner_and_association(owner_association)
owner_name = name_of_auto_action_for(owner_association)
refl = model.reflections[owner_association]
owner_name = refl.macro == :has_many ? owner_association.to_s.singularize : owner_association
id = params["#{owner_name}_id"]
owner = refl.klass.find(id)
instance_variable_set("@#{owner_association}", owner)
[owner, owner.send(model.reverse_reflection(owner_association).name)]
end

def name_of_auto_action_for(owner_association)
model.reflections[owner_association].macro == :has_many ? owner_association.to_s.singularize : owner_association
end

# --- Action implementations --- #

Expand Down Expand Up @@ -522,17 +525,17 @@ def hobo_create(*args, &b)
end


def hobo_create_for(owner, *args, &b)
def hobo_create_for(owner_association, *args, &b)
options = args.extract_options!
owner, association = find_owner_and_association(owner)
owner, association = find_owner_and_association(owner_association)
attributes = options[:attributes] || attribute_parameters || {}
if self.this ||= args.first
this.user_update_attributes(current_user, attributes)
else
self.this = association.new(attributes)
this.save
end
create_response(:"new_for_#{owner}", options, &b)
create_response(:"new_for_#{name_of_auto_action_for(owner_association)}", options, &b)
end


Expand Down

0 comments on commit 2ce25a7

Please sign in to comment.