I am using my rake console pry session to test out a class I have created for a CLI application I am making. Everytime I type "City.new" I expect to see nil attributes as instructed but I get a:
City.new
NameError: uninitialized constant City
What are common reasons for getting this error if I defined my class in another file. How can I fix this issue?
Thanks so much
I came across the same issue, I had not generated the controller for City model. Try that to see if will work
I am trying to send mail in production but it is throwing Activejob deserailization error.sidekiq is running in background. I have added sidekiq gem. I wrote one method in comment_notification.rb for sending email to the user. Then in controller in create action I have added this
def create
CommentNotification.send_comment_mail(#current_user).deliver_later(wait: 1.minute)
end
def send_comment_email(current_user)
mail( to: current_user.email,
:subject => "commented on post",
:from => "<noreply#xxx.com>")
end
It was working fine in local server but in production I am getting this error
/home/apps/commentpost/shared/bundle/ruby/2.3.0/gems/sidekiq-4.2.3/lib/sidekiq/processor.rb:69:in `run'
/home/apps/commentpost/shared/bundle/ruby/2.3.0/gems/sidekiq-4.2.3/lib/sidekiq/util.rb:17:in `watchdog'
/home/apps/commentpost/shared/bundle/ruby/2.3.0/gems/sidekiq-4.2.3/lib/sidekiq/util.rb:25:in `block in safe_thread'
2016-11-18T06:47:16.162Z 19093 TID-uw66g ActionMailer::DeliveryJob JID-e56b150964abf082e78089d9 INFO: start
2016-11-18T06:47:16.167Z 19093 TID-uw66g ActionMailer::DeliveryJob JID-e56b150964abf082e78089d9 INFO: fail: 0.005 sec
2016-11-18T06:47:16.167Z 19093 TID-uw66g WARN: {"context":"Job raised exception","job":{"class":"ActiveJob::QueueAdapters::SidekiqAdapter::JobWrapper","wrapped":"ActionMailer::DeliveryJob","queue":"mailers","args":[{"job_class":"ActionMailer::DeliveryJob","job_id":"96e06bc6-1380-47b9-9393-9727868b3897","queue_name":"mailers","priority":null,"arguments":["CommentNotification","send_comment_email","deliver_later",{"_aj_globalid":"gid://commentpost/comment/40"},{"_aj_globalid":"gid://commentpost/User/20"}],"locale":"en"}],"retry":true,"jid":"e56b150964abf082e78089d9","created_at":1479450405.8364522,"enqueued_at":1479451636.1602836,"error_message":"Error while trying to deserialize arguments: Couldn't find Comment with 'id'=40","error_class":"ActiveJob::DeserializationError","failed_at":1479450405.8429642,"retry_count":6,"retried_at":1479451636.1668367},"jobstr":"{\"class\":\"ActiveJob::QueueAdapters::SidekiqAdapter::JobWrapper\",\"wrapped\":\"ActionMailer::DeliveryJob\",\"queue\":\"mailers\",\"args\":[{\"job_class\":\"ActionMailer::DeliveryJob\",\"job_id\":\"96e06bc6-1380-47b9-9393-9727868b3897\",\"queue_name\":\"mailers\",\"priority\":null,\"arguments\":[\"CommentNotification\",\"send_comment_email\",\"deliver_later\",{\"_aj_globalid\":\"gid://commentpost/comment/40\"},{\"_aj_globalid\":\"gid://commentpost/User/20\"}],\"locale\":\"en\"}],\"retry\":true,\"jid\":\"e56b150964abf082e78089d9\",\"created_at\":1479450405.8364522,\"enqueued_at\":1479451636.1602836,\"error_message\":\"Error while trying to deserialize arguments: Couldn't find Comment with 'id'=40\",\"error_class\":\"ActiveJob::DeserializationError\",\"failed_at\":1479450405.8429642,\"retry_count\":5,\"retried_at\":1479450981.998904}"}
2016-11-18T06:47:16.167Z 19093 TID-uw66g WARN: ActiveJob::DeserializationError: Error while trying to deserialize arguments: Couldn't find Comment with 'id'=40
2016-11-18T06:47:16.167Z 19093 TID-uw66g WARN: /
Could anyone please help me regarding this doubt? For this I will be thankful.
As I understand correctly the create method in controller creates also the comment and sends the email for the freshly created comment?
Then it would be better to use a callback here.
We had the same issue in our project and we solved it by using something like that:
# in model
after_commit :send_mail, on: :create
private
def send_mail
CommentNotification.send_comment_mail(campaign.user).deliver_later
end
Then you can be sure that the record really exists in the Database before the mail gets delivered.
The problem here is, that you run a Comment#create and enqueue the mail in the controller. Now it can happen, that Sidekiq runs the task before Rails commits the new comment.
And then you get exactly this error.
Regards,
spa
When I ran into an issue with seemingly simple errors being raised due to the record not being the database (it was!), I found out that my Sidekiq workers were running in test mode and were able to dequeue jobs whose database records were supposed to be in the development database.
I was able to debug this after some trial and error in the stack trace by inspecting ActiveRecord::Base.connection's connection_parameters instance variable - it was pointing to the test database!
Looking through the Sidekiq logs, I was able to see that it was starting up workers to execute jobs against the test environment and database. My specific issue was also caused by spring. Disabling its use by invoking bundle exec sidekiq ... instead of sprint sidekiq fixed my issue.
I'm running into a strange error... After I call a thrift method, all file IO I try to do fails with errors like:
log writing failed. undefined method `write_struct_begin'
This occurs if I try to do logger.info etc., or even if I just open a file directly, and try to write to it.
Totally stumped!
The problem was that the Thrift interface I was consuming defined a type called "File". As soon as I pulled in the generated Ruby code for this file it rewrote the built-in File class. It would be nice if ruby's thrift generator namespaced things better!
On Windows XP, in my vbscript, I am using
GetObject("winmgmts:\.\root\cimv2")
to get WMI service object, but always get error: (null): Invalid syntax. I checked the syntax, it should be ok. I even tried to rebuild the Repo as suggested here , but still got the same error. I guess it might be permission/security policy issue. Any suggestions?
Your syntax is wrong you are missing a \
instead use
GetObject("winmgmts:\\.\root\cimv2");
or even better you can get the instance of the WMI class directly including the WMI path
GetObject("winmgmts:\\.\root\cimv2:Win32_LogicalDisk='C:'")
I am using hominid gem for Rails 3 for to connect with MailChimP API. I write a class with many methods for my problem domain.
I need a rake task which run each X time. My problem is when i test the hominid methods.
Each X time hominid gem raise a exception with EOF Reached file error.
I test my methods many time without to change arguments. sometimes run very well while other times throw this exception.
I also test my methods calling from console and controller action.
There occurs same problem.
How could I sync hominid API calls?
Which could be the problem?
Thanks in advance