You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've been trying to set up a mapped entry with dynamic_entries: :auto, but if I try to access any of the entry's fields in the view, I get undefined method. I'm using Rails 3 (don't ask) and v1.0.0 of this Gem, here's my controller:
And the view that's trying to output the title field:
<%= @page.title%>
No matter what I try, I'm always getting this error:
undefined method `title' for #<ContentfulPage:0x007f4652d21370>
I've seen a few tickets here with people suffering similar issues, but they all appear to have been going about it the wrong way, or there was a bug which has since been fixed. Am I also doing this wrong?
Other things I've tried:
Inheriting the ContentfulPage model from Contentful::DynamicEntry
Contentful::Entry does not support field accessors, you have to either inherit from Contentful::DynamicEntry or avoid inheritance at all and use the built-in Contentful classes.
Unless you want to add custom behaviour, they should work out of the box.
In case of wanting custom behaviour, changing to inheriting Contentful::DynamicEntry should solve most of your problems.
@dlitvakb Hi David, thanks for that - unfortunately that's one of the things I've tried already, and I still couldn't get it to work!
What I've done instead is provided a list of fields for each class, and then during initialize I've looped through them and created dynamically named methods for each. That was the only thing I could think of to get it working for me!
If I've missed something obvious about inheriting from Contentful::DynamicEntry the please let me know, but for now I'm happy with this solution too :)
I've been trying to set up a mapped entry with
dynamic_entries: :auto
, but if I try to access any of the entry's fields in the view, I getundefined method
. I'm using Rails 3 (don't ask) andv1.0.0
of this Gem, here's my controller:The
ContentfulPage
model:The Entry returned from the API:
#<ContentfulPage: @fields={:title=>"Home", :url=>"/"} @sys={ ... }>
And the view that's trying to output the
title
field:No matter what I try, I'm always getting this error:
I've seen a few tickets here with people suffering similar issues, but they all appear to have been going about it the wrong way, or there was a bug which has since been fixed. Am I also doing this wrong?
Other things I've tried:
Contentful::DynamicEntry
property
fields to the modelinitialize
method from this comment on a closed issue: Custom-Resource Classes: undefined method `[]=' for nil:NilClass in resource_builder:182 #79 (comment)property
fields)I'm going round in circles and can't seem to figure this out. Any chance someone can help out please? :)
The text was updated successfully, but these errors were encountered: