Using rails_admin, I whenever I try to save an object that has a date field, I get the error message: undefined method 'year' for nil:NilClass. Not sure what's going on.
Turns out it's a bug that's introduced with Ruby 2.2.*
Not sure if it's on the rails_admin team's radar yet, but you can fix it by downgrading to 2.1.*
Related
ruby '2.5.1'
rails '5.1.7'
My project is for sound management. All uploaded files are in the cloud storage - sounds/sound images/album images and etc.
But some files on cloud storage are absent. And for following code in view:
.row
- #sounds.each do |sound|
.col-md-2
.play{ "image-src": "#{sound.image.url(:small)}", style: "background: url(#{sound.image.url(:small)});" }
I get following error:
ActionView::Template::Error (undefined method `public_url' for nil:NilClass)
There are a lot of such cycles (#sounds.each) in the project, so I would not want to rewrite each one.
How to write an error handler for such case? So that in absence of files in storage, sound is skipped.
Maybe there is a way to write code in application_controller.rb or something similar?
I use gem 'carrierwave-google-storage' for images and gem 'google-cloud-storage' for attachment.
It seems that there are some cases where the error ActionView::Template::Error (undefined method `public_url' for nil:NilClass) occurs.
Looking on the Community, it seems that there are some options/ways that can fix this error and it would depend on the way that your code and application is configured. For this reason, I would recommend you to take a look at the following posts and answers, to check if they help you. :)
ActionView::Template::Error: ActionView::Template::Error: undefined method `[]' for nil:NilClass
Railstutorial ActionView::Template::Error: undefined method `email' for nil:NilClass
Ruby on rails : undefined method `map' for nil:NilClass , what causes this? when i add record to table
Let me know if the information helped you!
Calling really_destroy! on an active record in order to hard delete the record throws the following exception. How can I resolve this?
https://github.com/radar/paranoia
myRecord.really_destroy!
NoMethodError: undefined method 'reflections' for #MyActiveRecord:0x00000102793aa8
from /Users/name/.rvm/gems/ruby-2.0.0-p451#company/gems/activemodel-4.1.4/lib/active_model/attribute_methods.rb:435:in `method_missing'
This was a bug in Paranoia library which is fixed on the latest version. It was due to a change in ActiveModel where reflections method is no longer an instance method, rather it's now a class method
I am using rails 3.2.16 and ruby 1.9.3
I get this error from the localhost browser after rails s.
undefined method `to_date' for nil:NilClass
like this
NoMethodError in Products#new
Showing /Users/main/railscasts-episodes/episode-350/store-
after/app/views/products/_form.html.erb where line #27 raised:
undefined method `to_date' for nil:NilClass
in irb> mode it works only when I
require 'date'
Now my question is about my rails project. In which file in my project I should add
require 'date'
I added it into my model it did not work. Or, maybe I need to install any specific gem? to make this work
The problem you have isn't an issue with to_date, it's a problem with the object you're trying to perform the method on
Your issue will either be:
You have not declared the variable / object
Your variable / object is not populated with any data
I'd highly recommend posting the controller action you're using to invoke the to_date method. Obviously, there may be an issue with the way you're calling it, but the immediate issue is you're trying to deal with an unpopulated variable
I have set up a staging instance of a rails 3.1 application on Heroku and everything seems to work fine except I'm getting a strange error when I try to send emails. I am using the sendgrid starter addon for email delivery. The full error is below:
NoMethodError: undefined method `index' for #<Mail::Message:0x000000048daf28>
/app/.bundle/gems/ruby/1.9.1/gems/mail-2.3.0/lib/mail/message.rb:1289:in `method_missing'
/app/.bundle/gems/ruby/1.9.1/gems/mail-2.3.0/lib/mail/encodings.rb:117:in `value_decode'
/app/.bundle/gems/ruby/1.9.1/gems/mail-2.3.0/lib/mail/encodings.rb:101:in `decode_encode'
/app/.bundle/gems/ruby/1.9.1/gems/mail-2.3.0/lib/mail/fields/unstructured_field.rb:74:in `do_decode'
if I just generate the message object without calling deliver on it and inspect it everything seems fine. I am not seeing this error on my production app. Can you tell me what this error means and how to resolve it? Thanks.
Got the same error on my local machine using Rails 3.0.11. It happened after I passed some object instead of a string to the mail :to attribute. So be sure that the :to attribute is a string!
mail(to: object.to_s)
A new version of Mail, Mail 2.4.0, was released this weekend. I would recommend upgrading to this latest version and seeing if that has fixed your issue.
This error was the result of using Class instead of Module when defining a mail helper I'd created.
This error happened because I was setting custom headers to an integer value. Using to_s on these values resolved the issue for me.
I had a similar problem. However, the error I received was:
NoMethodError (undefined method `ascii_only?' for nil:NilClass)
My problem was I had:
mail(to: emails,....)
And my variable "emails" was actually an array, instead of being one single string of emails.
I am getting undefined method [] for true:TrueClass error while running the rake task in acts_as_recommendable plugin. The error points to the following line.
items = options[:on_class].find(:all).collect(&:id)
Can someone please tell what am i doing incorrectly.
options is probably defined as true. We can't really know why without more information.