Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use ActiveRecord::Reflection::AssociationReflection to create object #3

Open
outputstream opened this issue Oct 27, 2009 · 2 comments

Comments

@outputstream
Copy link

add_nested_fields.rb line 8 should be

:object => form_builder.object.class.reflect_on_association(field).klass.new

instead of

:object => field.to_s.classify.constantize.new

@miletbaker
Copy link
Owner

Hi,

I am happy to amend but would appreciate you clarifying what issues this overcomes?

Regards,
Jon

@outputstream
Copy link
Author

Hi, jon

for example

#Model

class User < ActiveRecord::Base

has_many :addresses

has_many :permissions, :class_name => "SystemPermission"

end

class User::Address < ActiveRecord::Base

belongs_to :user

end

has_many :address is automatic map to Address or ::Address or User::Address

#View

<%= add_nested_fields_for(f, :addresses, 'addresses' ) %>
Undefined constant Address
if use reflection, the class is User::Address

<%= add_nested_fields_for(f, :permissions, 'permissions' ) %>
Undefined constant Permission
if use reflection, the class is SystemPermission

enjoy,
Anuwat

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants