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

Contentful::Array does not implement #to_ary #200

Closed
arielkirkwood opened this issue May 7, 2019 · 3 comments · Fixed by #231
Closed

Contentful::Array does not implement #to_ary #200

arielkirkwood opened this issue May 7, 2019 · 3 comments · Fixed by #231

Comments

@arielkirkwood
Copy link

Hi folks, thanks for your hard work on this gem and the other Ruby client libraries!

I'm working with a Rails 4.2.11.1 project and the latest version of contentful_rails (0.4.2), which bundles contentful_model (1.0.1) and contentful (2.12.0). When I retrieve a collection of entries, I get a Contentful::Array object returned; within Rails, I'd like to be able to pass this object to the render method in my view to render a view template for each element of the array. To this end, my Contentful model has extend ActiveModel::Naming and include ActiveModel::Conversion implemented so that Rails knows how to find an associated view template for a given Contentful model; where I'm getting stuck is the initial render call with the Contentful::Array as an argument. Rails tries to figure out if the argument is a single object or a collection, using respond_to?(:to_ary) as a test (source).

Since Contentful::Array does not implement to_ary, Rails thinks it is a singular object, but since Contentful::Array does not implement to_partial_path, I get the usual error: '<Contentful::Array total=3 skip=0 limit=100>' is not an ActiveModel-compatible object. It must implement :to_partial_path.

Let me know if there's any further details I can provide about my use case :)

@arielkirkwood
Copy link
Author

arielkirkwood commented May 7, 2019

In case anyone else needs a work around, instead of doing

<%= render @collection %>

where @collection is a Contentful::Array, I'm doing

<%= render @collection.to_a %>

@arielkirkwood
Copy link
Author

@dlitvakb @pxlpnk My understanding is this wouldn't be a huge lift, would you like me to put together a PR?

@dlitvakb
Copy link
Contributor

Hey @arielkirkwood,

If you can that'd be great, since I don't quite understand what the issue is.

Cheers

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

Successfully merging a pull request may close this issue.

2 participants