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

Rails 4 and associations #61

Closed
boblin opened this issue Jul 16, 2013 · 3 comments · Fixed by #66
Closed

Rails 4 and associations #61

boblin opened this issue Jul 16, 2013 · 3 comments · Fixed by #66

Comments

@boblin
Copy link

boblin commented Jul 16, 2013

Hi,
I have trouble with association method in Rails 4.0.0 using like this:

class Group < ActiveRecord::Base
  has_many :members, class_name: 'User'
end
<%= show_for @group do |u| %>
    <%= u.association :members %>
<% end %>

It shows only:

Members: User

I found in show_for lib this:

sample = association.is_a?(Array) ? association.first : association

https://github.com/plataformatec/show_for/blob/master/lib/show_for/association.rb#L41

association was Array in rails 3.x, but since 4.0 is CollectionProxy.

Rasil 3:

Group.first.members.class
=> Array

Rails 4:

> Group.first.members.class 
=> ActiveRecord::Associations::CollectionProxy::ActiveRecord_Associations_CollectionProxy_User

So it looks that instead of

association.is_a?(Array)

there should be

association.is_a?(ActiveRecord::Associations::CollectionProxy)

.. at least for Rails 4

rafaelfranca added a commit that referenced this issue Sep 21, 2013
Rails 4 returns a CollectionProxy object when you call the association
method, so we need to check if the object we have respond to some
methods instead of checking if it is an Array

Fixed #61
durandom pushed a commit to durandom/show_for that referenced this issue Oct 15, 2013
Rails 4 returns a CollectionProxy object when you call the association
method, so we need to check if the object we have respond to some
methods instead of checking if it is an Array

Fixed heartcombo#61
@carlosantoniodasilva
Copy link
Member

@boblin should be hopefully fixed on master, please let us know if that works for you or anything is still a problem, thanks!

@boblin
Copy link
Author

boblin commented May 13, 2014

It Works! 👍

@carlosantoniodasilva
Copy link
Member

Awesome, thanks for reporting back.

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

Successfully merging a pull request may close this issue.

2 participants