-
Notifications
You must be signed in to change notification settings - Fork 63
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
*** NoMethodError Exception: undefined method
for empty field
#190
Comments
Hey @scott-silver,
I'm currently implementing a solution for your issue, that's going to be included in the next minor release, which I'm doing later today. The solution will be the following: By default, trying to access a field of an entry with an undefined value (the field is not sent back from the API), it will raise an Or, if you send If you try to access an unknown method on the entry and the content type doesn't have any matching field, it will return a The default behaviour will be to raise an exception due to the fact that right now it's already raising an exception, and not raising an exception is a breaking change, we're just changing the kind of exception raised. Hope this will solve you issue, Cheers PS: For the moment, to solve your issue without the need for update, you can do: either |
This has just been released. Cheers |
that's awesome, thanks @dlitvakb! |
Thanks. But if I want to wrap all the methods in one argument, is that possible? Such that I can have something like |
So I tried it, I figured out it only accepts one argument. Here is the error I go |
Ran into this issue regardless of the fix. Turns out, fields that are disabled in the response are not covered by |
I have a Contentful model (
blogAuthor
) that has an optional text field (bio
).If an
author
has a value forbio
, theContentful::Entry
for thatauthor
will have abio
method, and it will return the value when called.But if there is no
bio
, then theContentful::Entry
throws and error when you access thebio
method:From the docs, it looks like the solution to this issue is to set
dynamic_entries: :auto
, but enabling this option doesn't seem to change the type ofContentful::Entry
toContentful::DynamicEntry
(looks likeDynamic Entry
has possibly been removed?)@dlitvakb In version 2x of the gem, what is the correct way to access an optional field on
Contentful::Entry
that won't result in aNoMethodError
if the value isnil
?The text was updated successfully, but these errors were encountered: