Everything works fine in development mode, but when I try to start my app in production mode (RAILS_ENV=production script/server) I get the following error:
/opt/ruby1.8/lib/ruby/gems/1.8/gems/searchlogic-2.4.19/lib/searchlogic/named_scopes/conditions.rb:81:in `method_missing': protected method `scope' called for #<Class:0x7f41de524410> (NoMethodError)
from /opt/ruby1.8/lib/ruby/gems/1.8/gems/searchlogic-2.4.19/lib/searchlogic/named_scopes/association_conditions.rb:19:in `method_missing'
from /opt/ruby1.8/lib/ruby/gems/1.8/gems/searchlogic-2.4.19/lib/searchlogic/named_scopes/association_ordering.rb:27:in `method_missing'
from /opt/ruby1.8/lib/ruby/gems/1.8/gems/searchlogic-2.4.19/lib/searchlogic/named_scopes/ordering.rb:30:in `method_missing'
from /opt/ruby1.8/lib/ruby/gems/1.8/gems/searchlogic-2.4.19/lib/searchlogic/named_scopes/or_conditions.rb:28:in `method_missing'
from /opt/ruby1.8/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/base.rb:1959:in `method_missing_without_paginate'
from /opt/ruby1.8/lib/ruby/gems/1.8/gems/will_paginate-2.3.12/lib/will_paginate/finder.rb:170:in `method_missing'
from /opt/ruby1.8/lib/ruby/gems/1.8/gems/acts_as_commentable-3.0.0/lib/comment_methods.rb:12:in `included'
from .../app/models/comment.rb:2:in `include'
from .../app/models/comment.rb:2
from /opt/ruby1.8/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
from /opt/ruby1.8/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'...
Now it seems to me it that the acts_as_commentable gem is causing this. But how come, it works fine in development mode.
in development mode classes are loaded as you need them. In production, they're cached when rails starts.
I have found the error thanks to fl00r's comment:
show comment.rb (around line 2)
Line 2 in comment.rb was include ActsAsCommentable::Comment. That seemed a bit strange to me, so I took a look at the official documentation for the acts_as_commentable gem. That was the problem. It should have been acts_as_commentable instead. Must have copy-pasted it from somewhere.
Still, the mystery remains how it could have worked in development mode. Because of the class caching mentioned by annaswims?
Related
I am still learning Ruby (so I am a complete noob),
right now I have my app successfully running locally but when trying to opening the apps on heroku , in which I first perform the heroku run rake db:migrate I stumbled upon a problem.. it tells me :
Running `rake db:migrate` attached to terminal... up, run.2149
-- attr_accessible(:pName, :pQuantity, :pMeter, :pWeight, :pSellPrice, :pCategory, :pPic)
-- attr_accessible(:pName, :pQuantity, :pMeter, :pWeight, :pSellPrice, :pCategory, :pPic)
rake aborted!
NoMethodError: undefined method `attr_accessible' for #<ActiveRecord::Migration:0x007f2dc2ba45b8>
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.8/lib/active_record/migration.rb:648:in `block in method_missing'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.8/lib/active_record/migration.rb:621:in `block in say_with_time'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.8/lib/active_record/migration.rb:621:in `say_with_time'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.8/lib/active_record/migration.rb:641:in `method_missing'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.8/lib/active_record/migration.rb:406:in `method_missing'
/app/db/migrate/20150802134246_create_inventories.rb:2:in `<class:CreateInventories>'
/app/db/migrate/20150802134246_create_inventories.rb:1:in `<top (required)>'
/app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.8/lib/active_support/dependencies.rb:247:in `require'
/app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.8/lib/active_support/dependencies.rb:247:in `block in require'
/app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.8/lib/active_support/dependencies.rb:232:in `load_dependency'
/app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.8/lib/active_support/dependencies.rb:247:in `require'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.8/lib/active_record/migration.rb:761:in `load_migration'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.8/lib/active_record/migration.rb:757:in `migration'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.8/lib/active_record/migration.rb:752:in `disable_ddl_transaction'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.8/lib/active_record/migration.rb:1044:in `use_transaction?'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.8/lib/active_record/migration.rb:954:in `rescue in block in migrate'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.8/lib/active_record/migration.rb:951:in `block in migrate'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.8/lib/active_record/migration.rb:948:in `each'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.8/lib/active_record/migration.rb:948:in `migrate'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.8/lib/active_record/migration.rb:807:in `up'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.8/lib/active_record/migration.rb:785:in `migrate'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.8/lib/active_record/railties/databases.rake:34:in `block (2 levels) in <top (required)>'
Tasks: TOP => db:migrate
I have been trying to find out the reason, after wondering around I found out about change in rails 4.0.0 in that attr_accessible are no longer used and we should use strong parameter instead, So removing the attr_accessible from model will solve the problem...
However, I have an empty Model, there is no attr_accessible everywhere i look. (beside this is weird why my apps runs locally but not on heroku?)
I can't figured out why this error appear and where to look for solutions.. I have been trying to look at active_record file but am afraid of making any changes, any idea?
also, could anyone tell me any resources that can help me read this type of log errors? I have tried to read some articles but can't find one that is easy to understand for noobs like me... ;(
Glad I could help :)
As far as reading log errors goes, here's what I do. You're going to get a bunch of lines about files you have never touched. That's because although there's most likely an error in something you wrote, the error propagates through the entire Rails framework. That's why Rails is really cool: it does a lot of things for you, so you don't have to worry about them.
If the error is in code you wrote, that file should also be listed in the stack trace. So in this example, you have a bunch of /app/vendor/bundle/... (which I assumed you didn't touch), but then there is an /app/db/migrate/... (which is most likely something you created).
That leads me to think the error is in that file. Plus, it even gives you a line number (that's what the :2 is in create_inventories.rb:2). Granted those line numbers aren't always correct, but it should get you started in the right place!
I created my model whitch is Test, and everything is working ok when I am using it within browser, but when I try to do something with it from rails c, I got error.
1.9.3p125 :001 > t=Test.find(4)
NoMethodError: undefined method `find' for Test:Module
from (irb):1
from /home/dorijan/.rvm/gems/ruby-1.9.3-p125/gems/railties-3.2.3/lib/rails/commands/console.rb:47:in `start'
from /home/dorijan/.rvm/gems/ruby-1.9.3-p125/gems/railties-3.2.3/lib/rails/commands/console.rb:8:in `start'
from /home/dorijan/.rvm/gems/ruby-1.9.3-p125/gems/railties-3.2.3/lib/rails/commands.rb:41:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
So is there a way to disable this temporary? I know I shouldnt use this, but now it is too late...:(
Thank you
I dont know how to disable the Test module in rails console, sorry.
One workaround is to namespace your model into a new module and then at the console call from within its new name space see how to here
Problem may be that you have used 'test' which is on the rails reserved word wiki as possibly problematic see
rails reserved words
Try another model name not on reserved list
Looking at this solution https://github.com/tuupola/rack-facebook-method-fix it seems great except it omits what is probably obvious to most, but it's 5:30 in the morning and perhaps my brain is not working. In what file and where should I put the lines:
require "rack-facebook-method-fix"
use Rack::Facebook::MethodFix
? I assumed the top of application.rb but that gives me an error message:
/config/application.rb:5:in `<top (required)>': undefined method `use' for main:Object (NoMethodError)
Okay - so adding the above lines in the different environment files and modifyg the use line to read:
config.middleware.use Rack::Facebook::MethodFix
seems to work
When I'm trying to launch my production server on Rails 3.0.5, I keep getting this error:
/var/lib/gems/1.8/gems/activesupport-3.0.5/lib/active_support/core_ext/module/introspection.rb:70:in `const_get': no such file to load -- action_view/helpers/deprecated_block_helpers (LoadError)
from /var/lib/gems/1.8/gems/activesupport-3.0.5/lib/active_support/core_ext/module/introspection.rb:70:in `local_constants'
from /var/lib/gems/1.8/gems/activesupport-3.0.5/lib/active_support/core_ext/module/introspection.rb:70:in `each'
from /var/lib/gems/1.8/gems/activesupport-3.0.5/lib/active_support/core_ext/module/introspection.rb:70:in `local_constants'
from /var/lib/gems/1.8/gems/activesupport-3.0.5/lib/active_support/core_ext/module/introspection.rb:68:in `each'
from /var/lib/gems/1.8/gems/activesupport-3.0.5/lib/active_support/core_ext/module/introspection.rb:68:in `local_constants'
from /var/lib/gems/1.8/gems/activesupport-3.0.5/lib/active_support/core_ext/module/introspection.rb:86:in `local_constant_names'
from /var/lib/gems/1.8/gems/activesupport-3.0.5/lib/active_support/dependencies.rb:100:in `new_constants'
from /var/lib/gems/1.8/gems/activesupport-3.0.5/lib/active_support/dependencies.rb:91:in `each'
from /var/lib/gems/1.8/gems/activesupport-3.0.5/lib/active_support/dependencies.rb:91:in `new_constants'
from /var/lib/gems/1.8/gems/activesupport-3.0.5/lib/active_support/dependencies.rb:599:in `new_constants_in'
from /var/lib/gems/1.8/gems/activesupport-3.0.5/lib/active_support/dependencies.rb:225:in `load_dependency'
from /var/lib/gems/1.8/gems/activesupport-3.0.5/lib/active_support/dependencies.rb:239:in `require'
from /home/punkweek/punkweek/config.ru:3
from /var/lib/gems/1.8/gems/rack-1.2.2/lib/rack/builder.rb:46:in `instance_eval'
from /var/lib/gems/1.8/gems/rack-1.2.2/lib/rack/builder.rb:46:in `initialize'
from /home/punkweek/punkweek/config.ru:1:in `new'
from /home/punkweek/punkweek/config.ru:1
It seems there's a problem with a file, deprecated_block_helpers, which is not found in Rails. Anyone knows how to solve this problem?
Actually this is a bug in Rails 3.0.5 (it has been fixed in edge).
DeprecatedBlockHelpers is autoloaded in ActionView::Helpers, but the file itself was removed in 9de8305
This helper was designed to show a deprecation notice for using <% %> instead of <%= %> (or - instead of = in haml) for certain blocks. I'm not sure exactly which blocks the deprecation is for, but maybe take a look through your templates and see if you can trial-and-error this into working.
Alternatively, you can vendor Rails and remove the DeprecatedBlockHelpers autoload, or track edge Rails.
I'm running a Rails 3.0.0 application on Ruby 1.8.7-p174. Everything was going swimmingly until I tried to run some tests:
/Users/avand/.rvm/gems/ruby-1.8.7-p174/gems/activesupport-3.0.0/lib/active_support/core_ext/date/calculations.rb:9: undefined method `>>' for class `Date' (NameError)
from /Users/avand/.rvm/gems/ruby-1.8.7-p174/gems/activesupport-3.0.0/lib/active_support/ruby/shim.rb:12:in `require'
from /Users/avand/.rvm/gems/ruby-1.8.7-p174/gems/activesupport-3.0.0/lib/active_support/ruby/shim.rb:12
from /Users/avand/.rvm/gems/ruby-1.8.7-p174/gems/actionpack-3.0.0/lib/abstract_controller.rb:6:in `require'
from /Users/avand/.rvm/gems/ruby-1.8.7-p174/gems/actionpack-3.0.0/lib/abstract_controller.rb:6
I took a look into that Calculations class, noting that undef was being called with :>>. But Ruby 1.8.7 Dates don't have a >> method. I figured I'd wrap it with a condition: if respond_to?(:>>). Things broke further along this time:
/Users/avand/.rvm/gems/ruby-1.9.2-rc2/gems/activesupport-3.0.0/lib/active_support/core_ext/date/calculations.rb:91:in `alias_method': undefined method `+' for class `Date' (NameError)
from /Users/avand/.rvm/gems/ruby-1.9.2-rc2/gems/activesupport-3.0.0/lib/active_support/core_ext/date/calculations.rb:91:in `<class:Date>'
from /Users/avand/.rvm/gems/ruby-1.9.2-rc2/gems/activesupport-3.0.0/lib/active_support/core_ext/date/calculations.rb:7:in `<top (required)>'
from /Users/avand/.rvm/gems/ruby-1.9.2-rc2/gems/activesupport-3.0.0/lib/active_support/ruby/shim.rb:12:in `require'
from /Users/avand/.rvm/gems/ruby-1.9.2-rc2/gems/activesupport-3.0.0/lib/active_support/ruby/shim.rb:12:in `<top (required)>'
from /Users/avand/.rvm/gems/ruby-1.9.2-rc2/gems/actionpack-3.0.0/lib/abstract_controller.rb:6:in `require'
The second stack trace is Ruby 1.9.2. I'm getting the same error with Ruby 1.9.2 without my respond_to? check as Ruby 1.8.7 with it.
I commented out my Date extensions in lib. This only occurs in the test environment.
Thoughts?
So this may not be the most helpful answer but it's all I've been able to determine so far.
The file in question: activesupport-3.0.0/lib/active_support/core_ext/date/calculations.rb removes the definitions of :>> as you saw. If the file is require twice, the second loading of that file will fail due to the method no longer being defined on the Date class.
So why is this file being required twice? That I'm really not sure of. I've seen that the protection against this can be buggy (if you'd call it a bug, it may just be a limitation) when you specify the file with a full path once and then another time you depend on the LOAD_PATH having the correct folder in it to find you file that way.
I'd look through your code and see what is requiring either rails/all or activesupprt/railstie and hopefully you'll see two separate places that look slightly different. Also see if you're mucking with the LOAD_PATH anywhere between the two places.