NameError uninitialized constant in Jruy/Rails 3 - ruby-on-rails-3.1

I'm upgrading a project to Rails 3.1 and Jruby 1.6.4 from rails 2.6 I followed the Rails Handbook by Jeremy.
Now I'm getting some errors while booting the server.
NameError in Adm::AuthController#login
uninitialized constant Sentry::Dispatcher::Dispatcher
The error log
Started GET "/admin/login/en/sentry" for 127.0.0.1 at Wed Oct 05 16:59:00 -0400
2011
Processing by Adm::AuthController#login as HTML
Parameters: {"brand"=>"sentry", "language"=>"en"}
Completed 500 Internal Server Error in 9ms
NameError (uninitialized constant Sentry::Dispatcher::Dispatcher):
lib/sentry/dispatcher/application_dispatcher.rb:11:in `initialize'
app/controllers/application_controller.rb:90:in `before_interceptors'
Rendered C:/Users/matin/.pik/rubies/JRuby-164/lib/ruby/gems/1.8/gems/actionpack-
3.1.0/lib/action_dispatch/middleware/templates/rescues/_trace.erb (5.0ms)
Rendered C:/Users/matin/.pik/rubies/JRuby-164/lib/ruby/gems/1.8/gems/actionpack-
3.1.0/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb
(5.0ms)
Rendered C:/Users/matin/.pik/rubies/JRuby-164/lib/ruby/gems/1.8/gems/actionpack-
3.1.0/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb within re
scues/layout (30.0ms)

This works for me..
while upgrading you need to include the class as well, like(in this case)
include 'sentry/dispatcher/dispatcher'

Related

NameError - unitilaized constant - only in production

I have a ruby on rails app that is hosted on heroku. When I try to create an item running it in "development" mode, everything works great and there are no issues. However, when I switch the app to run in "production" mode I'm getting the following.
This was a Ruby 2.2.x upgraded to 2.5.x and rails 4.1 upgraded to 5.2.
Any ideas or suggestions on why this is failing in production but works fine in development?
Started POST "/items" for 1.2.3.4 at 2020-10-19 03:22:06 +0000
2020-10-19T03:22:06.870055+00:00 app[web.1]: Processing by ItemController#create as HTML
2020-10-19T03:22:06.870358+00:00 app[web.1]: Parameters: {###Redacted##}
2020-10-19T03:22:06.926046+00:00 app[web.1]: Completed 500 Internal Server Error in 54ms (ActiveRecord: 15.8ms)
2020-10-19T03:22:06.999133+00:00 app[web.1]: I, [2020-10-19T03:22:06.998984 #11] INFO -- : Sending event 18b887c876d4524b5cd46849a98aaeb1 to Sentry
2020-10-19T03:22:07.271068+00:00 app[web.1]:
2020-10-19T03:22:07.271478+00:00 app[web.1]: NameError (uninitialized constant #<Class:0x0000567238d68165>::Slug):
2020-10-19T03:22:07.276183+00:00 app[web.1]:
2020-10-19T03:22:07.276248+00:00 app[web.1]: app/models/item.rb:305:in `name_to_slug'
2020-10-19T03:22:07.276248+00:00 app[web.1]: app/models/item.rb:293:in `generate_slug'
I tracked this back to a custom class that was located in the "lib" folder. Moving from Rails 4 to 5 it seems like some behaviors changed with loading custom classes which needed to be accounted for:
https://gist.github.com/maxivak/381f1e964923f1d469c8d39da8e2522f

I cannot create new issue through with REST API

I'm troubled with redmine.
When I create new issue with Rest API(from Microsoft Excel), Internal Error 500 happened.
Seeing from production.log, "NoMethodError" is happened (see below message)
Started POST "/redmine/issues.xml?key=XXXXXXX" for XX.XX.XX.XXX at 2016-05-30 14:44:10 +0900
Processing by IssuesController#create as XML Parameters: {"issue"=>`
{"project_id"=>"mt001", "subject"=>"TEST_AI", "tracker_id"=>"6",
"category_id"=>"136", "assigned_to_id"=>"4", "fixed_version_id"=>"93",
"priority_id"=>"2", "parent_issue_id"=>nil,
"start_date"=>"2016-05-30", "due_date"=>"2016-06-01",
"description"=>"Redmine TEST AI", "status_id"=>"1"},
"key"=>"XXXXXXX(hidden for security"}
Current user: user1 (id=65)
Completed 500 Internal Server Error in 367ms (ActiveRecord: 19.9ms)
NoMethodError (undefined method `shared_versions' for nil:NilClass):
app/models/issue.rb:823:in `assignable_versions'
app/models/issue.rb:643:in `validate_issue'
app/controllers/issues_controller.rb:141:in `create'
lib/redmine/sudo_mode.rb:63:in `sudo_mode'
So, I tried to create new issew using web browser (IE11).
The ticket was created normally. Here is production.log.
Started POST "/redmine/projects/mt001/issues" for XX.XX.XX.XXX at 2016-05-30 14:58:23 +0900
Processing by IssuesController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"QF1BA5MgwysJsAiFfT/h95DeZ/VgzSGOnryR6xUn4mmWpf7EZ8XFJqpaye/ZLXrKR/wV00dKOz8KbhP94VcUyg==", "form_update_triggered_by"=>"", "issue"=>{"tracker_id"=>"6", "subject"=>"Test2", "description"=>"This is test", "status_id"=>"1", "priority_id"=>"2", "assigned_to_id"=>"4", "category_id"=>"132", "fixed_version_id"=>"127", "parent_issue_id"=>"", "start_date"=>"2016-05-30", "due_date"=>"2016-06-03", "custom_field_values"=>{"12"=>"", "41"=>""}}, "was_default_status"=>"1", "commit"=>"create", "project_id"=>"mt001"}
Current user: user1 (id=65)
Rendered mailer/_issue.text.erb (7.1ms)
Rendered mailer/issue_add.text.erb within layouts/mailer (9.8ms)
Rendered mailer/_issue.html.erb (3.0ms)
Rendered mailer/issue_add.html.erb within layouts/mailer (5.1ms)
Redirected to http://mydepartment.co.jp/redmine/issues/1717
Completed 302 Found in 3697ms (ActiveRecord: 130.3ms)
I already tried to migrate, clear cache.
What should I do next.
Here is my environment on RHEL7.2
Environment:
Redmine version 3.2.0.stable
Ruby version 2.2.4-p230 (2015-12-16) [x86_64-linux]
Rails version 4.2.5
Environment production
Database adapter Mysql2
SCM:
Subversion 1.7.14
Git 1.8.3.1
Filesystem
Redmine plugins:
redmine_export_with_journals 0.0.8
redmine_importer 1.2.2
redmine_local_avatars 1.0.0
redmine_xlsx_format_issue_exporter 0.1.2
sidebar_hide 0.0.7
Here is assinable_versions source-code
# Versions that the issue can be assigned to
def assignable_versions
return #assignable_versions if #assignable_versions
versions = project.shared_versions.open.to_a #Here is line823
if fixed_version
if fixed_version_id_changed?
# nothing to do
elsif project_id_changed?
if project.shared_versions.include?(fixed_version)
versions << fixed_version
end
else
versions << fixed_version
end
end
#assignable_versions = versions.uniq.sort
end
The error is occurring because project is nil and you are trying to call nil.shared_versions. So change the if condition:
if !project.shared_versions.nil?
versions = project.shared_versions.open.to_a
end
to as follows:
versions = project.shared_versions.open.to_a unless project.nil?
This will resolve the 'undefined method' error.
I've solved problem.
There is some difference of REST process.
At least redmine 2.4.4, I can use both project_id = identifier and project_id = project_id for issue create.
But, redmine 3.x, I can only use project_id = project_id for issue create.

Railscast geocoding missing JSON::ParserError constant

Replicating the geocoding example from Railscast #273 at http://railscasts.com/episodes/273-geocoder
under Rails 3.1rc4 using:
multi_json (1.0.3)
nifty-generators (0.4.6)
I get
NameError in LocationsController#create
uninitialized constant JSON::ParserError
Rails.root: ...
Application Trace | Framework Trace | Full Trace
app/controllers/locations_controller.rb:20:in `create'
This error occurred while loading the following files:
multi_json/engines/json_gem
I must be missing something which defines this. Anyone have an idea?rc4

RoR: Devise 500 error

I'm getting a 500 error when I go to /users/sign_in (or any other devise page).
This is all the log says:
Started GET "/users/sign_in" for 67.161.236.149 at Mon Jun 13 02:51:47 +0000 2011
Processing by Devise::SessionsController#new as HTML
Completed 500 Internal Server Error in 10ms
ActiveRecord::StatementInvalid (Could not find table 'users'):
Started GET "/users/sign_out" for 67.161.236.149 at Mon Jun 13 10:40:25 +0000 2011
Processing by Devise::SessionsController#destroy as HTML
Completed 500 Internal Server Error in 135ms
NameError (undefined local variable or method `root_path' for #<Devise::SessionsController:0x605f360>):
What is going wrong?
This looks suspicious:
ActiveRecord::StatementInvalid (Could not find table 'users'):
Have you run db:migrate since creating your User model?
Also,
NameError (undefined local variable or method `root_path' for #<Devise::SessionsController:0x605f360>)
suggests that you don't have a root path configured. This is something in routes.rb that matches requests to www.yourdomain.com/. You could use something like
root :to => "pages#home"
which would direct any request to www.yourdomain.com/ to the home action of the pages controller.

Ruby crashes on windows

I'm facing same problem described here: why-rails-fails-with-ruby-exe-has-encountered-a-problem-and-needs-to-close. that is ruby get crashed with following error:
ruby.exe has encountered a problem and needs to close. We are sorry for the inconvenience.
I'm asking this to add some details on it as that question was not asked by me I am not able to add information in it. So this is not duplicate.
Ruby crashes eventually no matter how I run it (in development or in production), but it seems to crash more often in production mode. Sometimes it will crash when I hold down the F5 key, but sometimes I have to hold and release it intermittently for a minute or two. It appears to be very dependent on timing, but I can usually make it crash in less than 60 seconds.
When I refresh the GET request is sent for 3 times as follows:
Started GET "/app/page" for 127.0.0.1 at 2011-02-23 10:57:35 +0530
Processing by AppController#page as HTML
Rendered pms/dashboard.html.erb within layouts/application (109.4ms)
Completed 200 OK in 141ms (Views: 140.6ms | ActiveRecord: 0.0ms)
Started GET "/app/page" for 127.0.0.1 at 2011-02-23 10:57:35 +0530
Processing by AppController#page as */*
Rendered pms/dashboard.html.erb within layouts/application (15.6ms)
Completed 200 OK in 187ms (Views: 187.5ms | ActiveRecord: 0.0ms)
Started GET "/app/page" for 127.0.0.1 at 2011-02-23 10:57:35 +0530
Processing by AppController#page as */*
Rendered pms/dashboard.html.erb within layouts/application (15.6ms)
Completed 200 OK in 219ms (Views: 218.7ms | ActiveRecord: 0.0ms)
And if I rapidly refresh the page get following error in one of or all the 3 request:
ERROR Errno:ECONNABORTED: An established connection was aborted by the software in your host machine:
c:/Ruby/lib/1.9.1/webrick/httpresponse.rb:323:in 'write'
c:/Ruby/lib/1.9.1/webrick/httprespose.rb:323:in '<<'
c:/Ruby/lib/1.9.1/webrick/httprespose.rb:323:in '_write_data'
c:/Ruby/lib/1.9.1/webrick/httprespose.rb:295:in 'send_body_string'
c:/Ruby/lib/1.9.1/webrick/httprespose.rb:186:in 'send_body'
c:/Ruby/lib/1.9.1/webrick/httprespose.rb:103:in 'send_response'
c:/Ruby/lib/1.9.1/webrick/httpserver.rb:86:in 'run'
ERROR Errno:ECONNABORTED: An established connection was aborted by the software in your host machine:
c:/Ruby/lib/1.9.1/webrick/httpserver.rb:56:in 'eof?'
c:/Ruby/lib/1.9.1/webrick/httpserver.rb:56:in 'run'
c:/Ruby/lib/1.9.1/webrick/server.rb:183:in 'block in start_thread'
INFO going to shutdown....
INFO WEBrick::HTTPServer#start done
When I started to get this error?
When I added images, css and javascript in my project I started to get this error. I also tried by removing one of this 3 and see who causes the error but every time my ruby.exe get crashed and i see the error:
ruby.exe has encountered a problem and needs to close. We are sorry for the inconvenience.
How can I solve this?
When I start server following is printed on console:
=>Booting WEBrick
=>Rails 3.0.3 application starting in development on http://0.0.0.0:3000
=>Call with -d to detach
=>Ctrl-C to shutdown server
[2011-02-23 10:59:22] INFO WEBrick 1.3.1
[2011-02-23 10:59:22] INFO ruby 1.9.2 (2010-08-18) [i386-mingw32]
[2011-02-23 10:59:22] INFO WEbrick::HTTPServer#start: pid:2448 port=3000
Output of ruby -v
ruby 1.9.2p0 (2010-08-18) [i386-mingw32]
... except the installer is now ALSO the crashing 1.9.2-p290
Workaround:
Add (or change)
config.log_level = :warn
in config/environments/development.rb
(not my solution - found it in another thread)
Running 1.9.2 on windows puts you in a REALLY small minority of users. If you don't have an explicit need for 1.9, I'd use 1.8.7. Specifically, I'd use the package from RailsInstaller: http://railsinstaller.org/
i got the same crashes on windows 7 with 1.9.2-p290. someone said to clear development.log file. i can't believe but after deleting my 12mb development.log everything works fine.
it is possible that a native (C) extension is failing and bringing the whole ruby down; in my case it was sql server adapter looping indefinitely/using whole heap; after we traced and fixed the bug in the adapter (https://github.com/rails-sqlserver/tiny_tds/pull/124) it does not fail again

Resources