rails sum multiple fields - sql

I'm trying to do this supposingly simple operation in rails:
self.timesheets.select("sum(total) as total, sum(quantity) as quantity").first where self is a project
When I do it in console mode, it works but it renders me 3 columns:
[#<Timesheet id: nil, quantity: 120.1, total: 6245.2>]
When I run it in the app, I get this error message:
PG::GroupingError - ERROR: column "timesheets.id" must appear in the GROUP BY clause or be used in an aggregate function
LINE 1: ..." WHERE "timesheets"."project_id" = $1 ORDER BY "timesheet...
^
:
activerecord (4.0.0) lib/active_record/connection_adapters/postgresql_adapter.rb:811:in `prepare_statement'
activerecord (4.0.0) lib/active_record/connection_adapters/postgresql_adapter.rb:772:in `exec_cache'
schema_plus (1.3.1) lib/schema_plus/active_record/connection_adapters/postgresql_adapter.rb:231:in `exec_cache_with_schema_plus'
activerecord (4.0.0) lib/active_record/connection_adapters/postgresql/database_statements.rb:139:in `block in exec_query'
activerecord (4.0.0) lib/active_record/connection_adapters/abstract_adapter.rb:425:in `block in log'
activesupport (4.0.0) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activerecord (4.0.0) lib/active_record/connection_adapters/abstract_adapter.rb:420:in `log'
activerecord (4.0.0) lib/active_record/connection_adapters/postgresql/database_statements.rb:137:in `exec_query'
activerecord (4.0.0) lib/active_record/connection_adapters/postgresql_adapter.rb:885:in `select'
activerecord (4.0.0) lib/active_record/connection_adapters/abstract/database_statements.rb:24:in `select_all'
activerecord (4.0.0) lib/active_record/connection_adapters/abstract/query_cache.rb:61:in `block in select_all'
activerecord (4.0.0) lib/active_record/connection_adapters/abstract/query_cache.rb:76:in `cache_sql'
activerecord (4.0.0) lib/active_record/connection_adapters/abstract/query_cache.rb:61:in `select_all'
activerecord (4.0.0) lib/active_record/querying.rb:36:in `find_by_sql'
activerecord (4.0.0) lib/active_record/relation.rb:585:in `exec_queries'
activerecord (4.0.0) lib/active_record/relation.rb:471:in `load'
activerecord (4.0.0) lib/active_record/relation.rb:220:in `to_a'
activerecord (4.0.0) lib/active_record/relation/finder_methods.rb:325:in `find_first'
activerecord (4.0.0) lib/active_record/relation/finder_methods.rb:90:in `first'
activerecord-deprecated_finders (1.0.3) lib/active_record/deprecated_finders/relation.rb:129:in `first'
app/models/project.rb:27:in `recalc_spendings'
app/models/timesheet.rb:44:in `escalate_sums'
activesupport (4.0.0) lib/active_support/callbacks.rb:452:in `_run__1475279931726113629__save__callbacks'
activesupport (4.0.0) lib/active_support/callbacks.rb:80:in `run_callbacks'
activerecord (4.0.0) lib/active_record/callbacks.rb:299:in `create_or_update'
activerecord (4.0.0) lib/active_record/persistence.rb:106:in `save'
activerecord (4.0.0) lib/active_record/validations.rb:51:in `save'
activerecord (4.0.0) lib/active_record/attribute_methods/dirty.rb:32:in `save'
activerecord (4.0.0) lib/active_record/transactions.rb:270:in `block (2 levels) in save'
activerecord (4.0.0) lib/active_record/transactions.rb:326:in `block in with_transaction_returning_status'
activerecord (4.0.0) lib/active_record/connection_adapters/abstract/database_statements.rb:202:in `block in transaction'
activerecord (4.0.0) lib/active_record/connection_adapters/abstract/database_statements.rb:210:in `within_new_transaction'
activerecord (4.0.0) lib/active_record/connection_adapters/abstract/database_statements.rb:202:in `transaction'
activerecord (4.0.0) lib/active_record/transactions.rb:209:in `transaction'
activerecord (4.0.0) lib/active_record/transactions.rb:323:in `with_transaction_returning_status'
activerecord (4.0.0) lib/active_record/transactions.rb:270:in `block in save'
activerecord (4.0.0) lib/active_record/transactions.rb:281:in `rollback_active_record_state!'
activerecord (4.0.0) lib/active_record/transactions.rb:269:in `save'
app/controllers/timesheets_controller.rb:73:in `block in create'
actionpack (4.0.0) lib/action_controller/metal/mime_responds.rb:363:in `retrieve_collector_from_mimes'
actionpack (4.0.0) lib/action_controller/metal/mime_responds.rb:189:in `respond_to'
app/controllers/timesheets_controller.rb:72:in `create'
actionpack (4.0.0) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
actionpack (4.0.0) lib/abstract_controller/base.rb:189:in `process_action'
actionpack (4.0.0) lib/action_controller/metal/rendering.rb:10:in `process_action'
actionpack (4.0.0) lib/abstract_controller/callbacks.rb:18:in `block in process_action'
activesupport (4.0.0) lib/active_support/callbacks.rb:463:in `_run__3822865716334379624__process_action__callbacks'
activesupport (4.0.0) lib/active_support/callbacks.rb:80:in `run_callbacks'
actionpack (4.0.0) lib/abstract_controller/callbacks.rb:17:in `process_action'
actionpack (4.0.0) lib/action_controller/metal/rescue.rb:29:in `process_action'
actionpack (4.0.0) lib/action_controller/metal/instrumentation.rb:31:in `block in process_action'
activesupport (4.0.0) lib/active_support/notifications.rb:159:in `block in instrument'
activesupport (4.0.0) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (4.0.0) lib/active_support/notifications.rb:159:in `instrument'
actionpack (4.0.0) lib/action_controller/metal/instrumentation.rb:30:in `process_action'
actionpack (4.0.0) lib/action_controller/metal/params_wrapper.rb:245:in `process_action'
activerecord (4.0.0) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
actionpack (4.0.0) lib/abstract_controller/base.rb:136:in `process'
actionpack (4.0.0) lib/abstract_controller/rendering.rb:44:in `process'
actionpack (4.0.0) lib/action_controller/metal.rb:195:in `dispatch'
actionpack (4.0.0) lib/action_controller/metal/rack_delegation.rb:13:in `dispatch'
actionpack (4.0.0) lib/action_controller/metal.rb:231:in `block in action'
actionpack (4.0.0) lib/action_dispatch/routing/route_set.rb:80:in `dispatch'
actionpack (4.0.0) lib/action_dispatch/routing/route_set.rb:48:in `call'
actionpack (4.0.0) lib/action_dispatch/journey/router.rb:71:in `block in call'
actionpack (4.0.0) lib/action_dispatch/journey/router.rb:59:in `call'
actionpack (4.0.0) lib/action_dispatch/routing/route_set.rb:655:in `call'
newrelic_rpm (3.6.9.171) lib/new_relic/rack/error_collector.rb:50:in `call'
newrelic_rpm (3.6.9.171) lib/new_relic/rack/agent_hooks.rb:28:in `call'
newrelic_rpm (3.6.9.171) lib/new_relic/rack/browser_monitoring.rb:23:in `call'
newrelic_rpm (3.6.9.171) lib/new_relic/rack/developer_mode.rb:42:in `call'
warden (1.2.3) lib/warden/manager.rb:35:in `block in call'
warden (1.2.3) lib/warden/manager.rb:34:in `call'
rack (1.5.2) lib/rack/etag.rb:23:in `call'
rack (1.5.2) lib/rack/conditionalget.rb:35:in `call'
rack (1.5.2) lib/rack/head.rb:11:in `call'
remotipart (1.0.5) lib/remotipart/middleware.rb:30:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/params_parser.rb:27:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/flash.rb:241:in `call'
rack (1.5.2) lib/rack/session/abstract/id.rb:225:in `context'
rack (1.5.2) lib/rack/session/abstract/id.rb:220:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/cookies.rb:486:in `call'
activerecord (4.0.0) lib/active_record/query_cache.rb:36:in `call'
activerecord (4.0.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:626:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
activesupport (4.0.0) lib/active_support/callbacks.rb:373:in `_run__1689713881852047757__call__callbacks'
activesupport (4.0.0) lib/active_support/callbacks.rb:80:in `run_callbacks'
actionpack (4.0.0) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/reloader.rb:64:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/remote_ip.rb:76:in `call'
better_errors (1.0.1) lib/better_errors/middleware.rb:84:in `protected_app_call'
better_errors (1.0.1) lib/better_errors/middleware.rb:79:in `better_errors_call'
better_errors (1.0.1) lib/better_errors/middleware.rb:56:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
railties (4.0.0) lib/rails/rack/logger.rb:38:in `call_app'
railties (4.0.0) lib/rails/rack/logger.rb:21:in `block in call'
activesupport (4.0.0) lib/active_support/tagged_logging.rb:67:in `block in tagged'
activesupport (4.0.0) lib/active_support/tagged_logging.rb:25:in `tagged'
activesupport (4.0.0) lib/active_support/tagged_logging.rb:67:in `tagged'
railties (4.0.0) lib/rails/rack/logger.rb:21:in `call'
quiet_assets (1.0.2) lib/quiet_assets.rb:18:in `call_with_quiet_assets'
actionpack (4.0.0) lib/action_dispatch/middleware/request_id.rb:21:in `call'
rack (1.5.2) lib/rack/methodoverride.rb:21:in `call'
rack (1.5.2) lib/rack/runtime.rb:17:in `call'
activesupport (4.0.0) lib/active_support/cache/strategy/local_cache.rb:83:in `call'
rack (1.5.2) lib/rack/lock.rb:17:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/static.rb:64:in `call'
railties (4.0.0) lib/rails/engine.rb:511:in `call'
railties (4.0.0) lib/rails/application.rb:97:in `call'
rack (1.5.2) lib/rack/content_length.rb:14:in `call'
thin (1.6.1) lib/thin/connection.rb:82:in `block in pre_process'
thin (1.6.1) lib/thin/connection.rb:80:in `pre_process'
thin (1.6.1) lib/thin/connection.rb:55:in `process'
thin (1.6.1) lib/thin/connection.rb:41:in `receive_data'
eventmachine (1.0.3) lib/eventmachine.rb:187:in `run'
thin (1.6.1) lib/thin/backends/base.rb:73:in `start'
thin (1.6.1) lib/thin/server.rb:162:in `start'
rack (1.5.2) lib/rack/handler/thin.rb:16:in `run'
rack (1.5.2) lib/rack/server.rb:264:in `start'
railties (4.0.0) lib/rails/commands/server.rb:84:in `start'
railties (4.0.0) lib/rails/commands.rb:78:in `block in <top (required)>'
railties (4.0.0) lib/rails/commands.rb:73:in `<top (required)>'
bin/rails:4:in `<top (required)>'
ruby-debug-ide (0.4.22) lib/ruby-debug-ide.rb:86:in `debug_program'
ruby-debug-ide (0.4.22) bin/rdebug-ide:110:in `<top (required)>'
-e:1:in `<main>'
I'm not really surprised by this message as the id is added to the query'result.
But why is it added by activerecord and how can I solve this?
Thanks!
EDIT
Thanks to PriteshJ, I understood that the ID was included by the "first" statement added at the end of my query to tell activerecord that it is a single record, not a collection.
So I know that I must get rid of first clause but when I do this, I get another error message:
NoMethodError: undefined method `total' for #<ActiveRecord::Relation::ActiveRecord_Relation_Timesheet:0x007fe73da50470>
from /usr/local/rvm/gems/ruby-2.0.0-p0/gems/activerecord-4.0.0/lib/active_record/relation/delegation.rb:121:in `method_missing'
This is normal because it is looking into a relation instead of a single record but I don't know how to solve it.
Should be simple though...

It looks like you are ordering the results by timesheets.id or you have some default order scope or somewhere you are adding a order.
Remove the ordering or add the column to select by which you are ordering the query.
UPDATE:
try using
self.timesheets.select("sum(total) as total, sum(quantity) as quantity").to_a.first
.first in activerecord will try to sort the query and pick first element so first by using .to_a take the result first then do .first

I think select is not the method you want to be using since you're not actually selecting a row in the db.
Perhaps sum is what you want (If I understand the problem correctly).
Would this work for you?:
total = project.timesheets.sum(:total)
quantity = project.timesheets.sum(:quantity)

With squeel gem, it is easy.
self.timesheets.select{[sum(:total).as(:total), sum(:quantity).as(:quantity)]}

self.timesheets.pluck("sum(total)", "sum(quantity)")

If you use select it will attempt to build a model with the fields you specified. You would be better of using pluck as suggested by jackpipe. However, I would make one alteration - methods like sum will return 0 if there are no records, but pluck will return nil, so to overcome that you could try this:
total, quantity = self.timesheets.pluck("sum(total)", "sum(quantity)").first.map(&:to_i)

Related

Ruby on Rails page load error "could not connect to server: Connection refused (0x0000274D/10061)"

When I run my "rails server" command, and go to my web page, I get this error http://s7.postimg.org/jcxqxl3gr/image.png I am using Postgresql and have only installed the twitter-bootstrap-rails gem. I am using rails 4.0.0. Why is it showing me this error? I installed everything through railsinstaller, but update to 4.0.0 through rubygems.
Any help would be aprreciated,
Amar
EDIT:
Sorry for the late edit, but here is the current contents of my development log file:
Started GET "/" for 127.0.0.1 at 2013-07-02 09:39:00 +1200
PG::Error (could not connect to server: Connection refused (0x0000274D/10061)
Is the server running on host "localhost" (::1) and accepting
TCP/IP connections on port 5432?
could not connect to server: Connection refused (0x0000274D/10061)
Is the server running on host "localhost" (127.0.0.1) and accepting
TCP/IP connections on port 5432?
):
activerecord (4.0.0) lib/active_record/connection_adapters/postgresql_adapter.rb:825:in `initialize'
activerecord (4.0.0) lib/active_record/connection_adapters/postgresql_adapter.rb:825:in `new'
activerecord (4.0.0) lib/active_record/connection_adapters/postgresql_adapter.rb:825:in `connect'
activerecord (4.0.0) lib/active_record/connection_adapters/postgresql_adapter.rb:542:in `initialize'
activerecord (4.0.0) lib/active_record/connection_adapters/postgresql_adapter.rb:41:in `new'
activerecord (4.0.0) lib/active_record/connection_adapters/postgresql_adapter.rb:41:in `postgresql_connection'
activerecord (4.0.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:440:in `new_connection'
activerecord (4.0.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:450:in `checkout_new_connection'
activerecord (4.0.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:421:in `acquire_connection'
activerecord (4.0.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:356:in `block in checkout'
C:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
activerecord (4.0.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:355:in `checkout'
activerecord (4.0.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:265:in `block in connection'
C:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
activerecord (4.0.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:264:in `connection'
activerecord (4.0.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:546:in `retrieve_connection'
activerecord (4.0.0) lib/active_record/connection_handling.rb:79:in `retrieve_connection'
activerecord (4.0.0) lib/active_record/connection_handling.rb:53:in `connection'
activerecord (4.0.0) lib/active_record/query_cache.rb:51:in `restore_query_cache_settings'
activerecord (4.0.0) lib/active_record/query_cache.rb:43:in `rescue in call'
activerecord (4.0.0) lib/active_record/query_cache.rb:32:in `call'
activerecord (4.0.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:626:in `call'
activerecord (4.0.0) lib/active_record/migration.rb:369:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
activesupport (4.0.0) lib/active_support/callbacks.rb:373:in `_run__790143164__call__callbacks'
activesupport (4.0.0) lib/active_support/callbacks.rb:80:in `run_callbacks'
actionpack (4.0.0) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/reloader.rb:64:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/remote_ip.rb:76:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
railties (4.0.0) lib/rails/rack/logger.rb:38:in `call_app'
railties (4.0.0) lib/rails/rack/logger.rb:21:in `block in call'
activesupport (4.0.0) lib/active_support/tagged_logging.rb:67:in `block in tagged'
activesupport (4.0.0) lib/active_support/tagged_logging.rb:25:in `tagged'
activesupport (4.0.0) lib/active_support/tagged_logging.rb:67:in `tagged'
railties (4.0.0) lib/rails/rack/logger.rb:21:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/request_id.rb:21:in `call'
rack (1.5.2) lib/rack/methodoverride.rb:21:in `call'
rack (1.5.2) lib/rack/runtime.rb:17:in `call'
activesupport (4.0.0) lib/active_support/cache/strategy/local_cache.rb:83:in `call'
rack (1.5.2) lib/rack/lock.rb:17:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/static.rb:64:in `call'
railties (4.0.0) lib/rails/engine.rb:511:in `call'
railties (4.0.0) lib/rails/application.rb:97:in `call'
rack (1.5.2) lib/rack/lock.rb:17:in `call'
rack (1.5.2) lib/rack/content_length.rb:14:in `call'
rack (1.5.2) lib/rack/handler/webrick.rb:60:in `service'
C:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/webrick/httpserver.rb:138:in `service'
C:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/webrick/httpserver.rb:94:in `run'
C:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/webrick/server.rb:191:in `block in start_thread'
Rendered C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/actionpack-4.0.0/lib/action_dispatch/middleware/templates/rescues/_source.erb (1.0ms)
Rendered C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/actionpack-4.0.0/lib/action_dispatch/middleware/templates/rescues/_trace.erb (1.0ms)
Rendered C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/actionpack-4.0.0/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (1.0ms)
Rendered C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/actionpack-4.0.0/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb within rescues/layout (106.1ms)
I think that your postgres server is not running.Thats why you get this error try to run it.
you are using windows so try to check this link it will give you some hint
postgreSQL database service

how to use rails-api gem with CouchRest model

I'm trying to set up a rails API using the rails-api gem rails-api and couchrest model. Using rails-api strips out a lot of the middleware and modules and I believe that is why I'm getting the following error:
Started GET "/assets" for 127.0.0.1 at 2012-10-10 16:00:36 +0100
Connecting to database specified by database.yml
ActiveRecord::ConnectionNotEstablished (ActiveRecord::ConnectionNotEstablished):
activerecord (3.2.8) lib/active_record/connection_adapters/abstract/connection_pool.rb:404:in `retrieve_connection'
activerecord (3.2.8) lib/active_record/connection_adapters/abstract/connection_specification.rb:170:in `retrieve_connection'
activerecord (3.2.8) lib/active_record/connection_adapters/abstract/connection_specification.rb:144:in `connection'
activerecord (3.2.8) lib/active_record/query_cache.rb:67:in `rescue in call'
activerecord (3.2.8) lib/active_record/query_cache.rb:61:in `call'
activerecord (3.2.8) lib/active_record/connection_adapters/abstract/connection_pool.rb:473:in `call'
actionpack (3.2.8) lib/action_dispatch/middleware/callbacks.rb:28:in `block in call'
activesupport (3.2.8) lib/active_support/callbacks.rb:405:in `_run__2405051170962911444__call__2117088860059348020__callbacks'
activesupport (3.2.8) lib/active_support/callbacks.rb:405:in `__run_callback'
activesupport (3.2.8) lib/active_support/callbacks.rb:385:in `_run_call_callbacks'
activesupport (3.2.8) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (3.2.8) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (3.2.8) lib/action_dispatch/middleware/reloader.rb:65:in `call'
actionpack (3.2.8) lib/action_dispatch/middleware/remote_ip.rb:31:in `call'
actionpack (3.2.8) lib/action_dispatch/middleware/debug_exceptions.rb:16:in `call'
actionpack (3.2.8) lib/action_dispatch/middleware/show_exceptions.rb:56:in `call'
railties (3.2.8) lib/rails/rack/logger.rb:26:in `call_app'
railties (3.2.8) lib/rails/rack/logger.rb:16:in `call'
actionpack (3.2.8) lib/action_dispatch/middleware/request_id.rb:22:in `call'
rack (1.4.1) lib/rack/runtime.rb:17:in `call'
activesupport (3.2.8) lib/active_support/cache/strategy/local_cache.rb:72:in `call'
rack (1.4.1) lib/rack/lock.rb:15:in `call'
actionpack (3.2.8) lib/action_dispatch/middleware/static.rb:62:in `call'
railties (3.2.8) lib/rails/engine.rb:479:in `call'
railties (3.2.8) lib/rails/application.rb:223:in `call'
rack (1.4.1) lib/rack/content_length.rb:14:in `call'
railties (3.2.8) lib/rails/rack/log_tailer.rb:17:in `call'
rack (1.4.1) lib/rack/handler/webrick.rb:59:in `service'
/Users/jason/.rvm/rubies/ruby-1.9.2-p320/lib/ruby/1.9.1/webrick/httpserver.rb:111:in `service'
/Users/jason/.rvm/rubies/ruby-1.9.2-p320/lib/ruby/1.9.1/webrick/httpserver.rb:70:in `run'
/Users/jason/.rvm/rubies/ruby-1.9.2-p320/lib/ruby/1.9.1/webrick/server.rb:183:in `block in start_thread'
Rendered /Users/jason/.rvm/gems/ruby-1.9.2-p320/gems/actionpack-3.2.8/lib/action_dispatch/middleware/templates/rescues/_trace.erb (0.9ms)
Rendered /Users/jason/.rvm/gems/ruby-1.9.2-p320/gems/actionpack-3.2.8/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (1.9ms)
Rendered /Users/jason/.rvm/gems/ruby-1.9.2-p320/gems/actionpack-3.2.8/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb within rescues/layout (8.1ms)
Can anyone point out what modules and middleware I would need to include to get it working?
Thanks

Redmine 2.0.0 plugin install error ActionController::RoutingError uninitialized constant

I have install Redmine 2.0.0 and try to Install plugin in plugins directory from github.
I had try to install two plugins Monitoring_Controlling and Redmine-Bulk-User-Assignments follow the installation steps written on github plugin but in both plugin getting same error and error is following
Started GET "/bulk_user_assignments" for 127.0.0.1 at Sat May 19 13:37:26 +0530 2012
ActionController::RoutingError (uninitialized constant BulkUserAssignmentsController):
activesupport (3.2.3) lib/active_support/inflector/methods.rb:218:in `constantize'
activesupport (3.2.3) lib/active_support/inflector/methods.rb:217:in `each'
activesupport (3.2.3) lib/active_support/inflector/methods.rb:217:in `constantize'
actionpack (3.2.3) lib/action_dispatch/routing/route_set.rb:69:in `controller_reference'
actionpack (3.2.3) lib/action_dispatch/routing/route_set.rb:54:in `controller'
actionpack (3.2.3) lib/action_dispatch/routing/route_set.rb:32:in `call'
journey (1.0.3) lib/journey/router.rb:68:in `call'
journey (1.0.3) lib/journey/router.rb:56:in `each'
journey (1.0.3) lib/journey/router.rb:56:in `call'
actionpack (3.2.3) lib/action_dispatch/routing/route_set.rb:600:in `call'
rack-openid (1.3.1) lib/rack/openid.rb:98:in `call'
actionpack (3.2.3) lib/action_dispatch/middleware/best_standards_support.rb:17:in `call'
rack (1.4.1) lib/rack/etag.rb:23:in `call'
rack (1.4.1) lib/rack/conditionalget.rb:25:in `call'
actionpack (3.2.3) lib/action_dispatch/middleware/head.rb:14:in `call'
actionpack (3.2.3) lib/action_dispatch/middleware/params_parser.rb:21:in `call'
actionpack (3.2.3) lib/action_dispatch/middleware/flash.rb:242:in `call'
rack (1.4.1) lib/rack/session/abstract/id.rb:205:in `context'
rack (1.4.1) lib/rack/session/abstract/id.rb:200:in `call'
actionpack (3.2.3) lib/action_dispatch/middleware/cookies.rb:338:in `call'
activerecord (3.2.3) lib/active_record/query_cache.rb:64:in `call'
activerecord (3.2.3) lib/active_record/connection_adapters/abstract/connection_pool.rb:467:in `call'
actionpack (3.2.3) lib/action_dispatch/middleware/callbacks.rb:28:in `call'
activesupport (3.2.3) lib/active_support/callbacks.rb:405:in `_run__108590059__call__4__callbacks'
activesupport (3.2.3) lib/active_support/callbacks.rb:405:in `send'
activesupport (3.2.3) lib/active_support/callbacks.rb:405:in `__run_callback'
activesupport (3.2.3) lib/active_support/callbacks.rb:385:in `_run_call_callbacks'
activesupport (3.2.3) lib/active_support/callbacks.rb:81:in `send'
activesupport (3.2.3) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (3.2.3) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (3.2.3) lib/action_dispatch/middleware/reloader.rb:65:in `call'
actionpack (3.2.3) lib/action_dispatch/middleware/remote_ip.rb:31:in `call'
actionpack (3.2.3) lib/action_dispatch/middleware/debug_exceptions.rb:16:in `call'
actionpack (3.2.3) lib/action_dispatch/middleware/show_exceptions.rb:56:in `call'
railties (3.2.3) lib/rails/rack/logger.rb:26:in `call_app'
railties (3.2.3) lib/rails/rack/logger.rb:16:in `call'
actionpack (3.2.3) lib/action_dispatch/middleware/request_id.rb:22:in `call'
rack (1.4.1) lib/rack/methodoverride.rb:21:in `call'
rack (1.4.1) lib/rack/runtime.rb:17:in `call'
activesupport (3.2.3) lib/active_support/cache/strategy/local_cache.rb:72:in `call'
rack (1.4.1) lib/rack/lock.rb:15:in `call'
actionpack (3.2.3) lib/action_dispatch/middleware/static.rb:62:in `call'
railties (3.2.3) lib/rails/engine.rb:479:in `call'
railties (3.2.3) lib/rails/application.rb:220:in `call'
rack (1.4.1) lib/rack/content_length.rb:14:in `call'
railties (3.2.3) lib/rails/rack/log_tailer.rb:14:in `call'
rack (1.4.1) lib/rack/handler/webrick.rb:59:in `service'
/usr/lib/ruby/1.8/webrick/httpserver.rb:104:in `service'
/usr/lib/ruby/1.8/webrick/httpserver.rb:65:in `run'
/usr/lib/ruby/1.8/webrick/server.rb:173:in `start_thread'
/usr/lib/ruby/1.8/webrick/server.rb:162:in `start'
/usr/lib/ruby/1.8/webrick/server.rb:162:in `start_thread'
/usr/lib/ruby/1.8/webrick/server.rb:95:in `start'
/usr/lib/ruby/1.8/webrick/server.rb:92:in `each'
/usr/lib/ruby/1.8/webrick/server.rb:92:in `start'
/usr/lib/ruby/1.8/webrick/server.rb:23:in `start'
/usr/lib/ruby/1.8/webrick/server.rb:82:in `start'
rack (1.4.1) lib/rack/handler/webrick.rb:13:in `run'
rack (1.4.1) lib/rack/server.rb:265:in `start'
railties (3.2.3) lib/rails/commands/server.rb:70:in `start'
railties (3.2.3) lib/rails/commands.rb:55
railties (3.2.3) lib/rails/commands.rb:50:in `tap'
railties (3.2.3) lib/rails/commands.rb:50
script/rails:6:in `require'
script/rails:6
Do I need to do anything else to install plugins in redmine 2 or write routes any other place.
One more thing both the plugin is written in rails 2 so I change the routes file to rails 3 routes file.
Plugins based on Redmine 1.x will break on 2.0
See the redmine2.0 release news --> http://www.redmine.org/news/66
The monitoring_controlling plugin is not Redmine2.0 compatible yet(unlilke advertised) and I have opened up an issue here -->
https://github.com/alexmonteiro/Redmine-Monitoring-Controlling/issues/17#issuecomment-5806223
You need to change the Route files(one of the changes). More for understanding the general scope of writing future proof plugin, this discussion might be of some use -->
http://www.redmine.org/issues/10813
Redmine Monitoring Controlling Plugin is ready to Redmine 2.0.
Check last commit on git repository: https://github.com/alexmonteiro/Redmine-Monitoring-Controlling

Rails 3 running on passenger, unknown attribute: session_id error

I'm running a rails 3 app on passenger. Periodically I get the following error when going to log in. It was happening seemingly random. It wasn't common at first and went away on its own. Now it's becoming a bigger issue. Any help would be appreciated. Thanks
ActiveRecord::UnknownAttributeError in LoginController#index
unknown attribute: session_id
Rails.root: /var/www/apps/myapp/releases/20120501181816
Application Trace | Framework Trace | Full Trace
activerecord (3.2.2) lib/active_record/attribute_assignment.rb:88:in `block in assign_attributes'
activerecord (3.2.2) lib/active_record/attribute_assignment.rb:78:in `each'
activerecord (3.2.2) lib/active_record/attribute_assignment.rb:78:in `assign_attributes'
activerecord (3.2.2) lib/active_record/base.rb:495:in `initialize'
activerecord (3.2.2) lib/active_record/session_store.rb:130:in `initialize'
activerecord (3.2.2) lib/active_record/session_store.rb:310:in `new'
activerecord (3.2.2) lib/active_record/session_store.rb:310:in `block in get_session'
activesupport (3.2.2) lib/active_support/benchmarkable.rb:50:in `silence'
activerecord (3.2.2) lib/active_record/session_store.rb:305:in `get_session'
rack (1.4.1) lib/rack/session/abstract/id.rb:246:in `load_session'
actionpack (3.2.2) lib/action_dispatch/middleware/session/abstract_store.rb:47:in `block in load_session'
actionpack (3.2.2) lib/action_dispatch/middleware/session/abstract_store.rb:55:in `stale_session_check!'
actionpack (3.2.2) lib/action_dispatch/middleware/session/abstract_store.rb:47:in `load_session'
rack (1.4.1) lib/rack/session/abstract/id.rb:130:in `load!'
rack (1.4.1) lib/rack/session/abstract/id.rb:126:in `load_for_write!'
rack (1.4.1) lib/rack/session/abstract/id.rb:71:in `[]='
actionpack (3.2.2) lib/action_dispatch/middleware/flash.rb:249:in `call'
rack (1.4.1) lib/rack/session/abstract/id.rb:205:in `context'
rack (1.4.1) lib/rack/session/abstract/id.rb:200:in `call'
actionpack (3.2.2) lib/action_dispatch/middleware/cookies.rb:338:in `call'
activerecord (3.2.2) lib/active_record/query_cache.rb:64:in `call'
activerecord (3.2.2) lib/active_record/connection_adapters/abstract/connection_pool.rb:443:in `call'
actionpack (3.2.2) lib/action_dispatch/middleware/callbacks.rb:28:in `block in call'
activesupport (3.2.2) lib/active_support/callbacks.rb:405:in `_run__1318401008379964085__call__2594406452281670030__callbacks'
activesupport (3.2.2) lib/active_support/callbacks.rb:405:in `__run_callback'
activesupport (3.2.2) lib/active_support/callbacks.rb:385:in `_run_call_callbacks'
activesupport (3.2.2) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (3.2.2) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (3.2.2) lib/action_dispatch/middleware/remote_ip.rb:31:in `call'
actionpack (3.2.2) lib/action_dispatch/middleware/debug_exceptions.rb:16:in `call'
actionpack (3.2.2) lib/action_dispatch/middleware/show_exceptions.rb:56:in `call'
railties (3.2.2) lib/rails/rack/logger.rb:26:in `call_app'
railties (3.2.2) lib/rails/rack/logger.rb:16:in `call'
actionpack (3.2.2) lib/action_dispatch/middleware/request_id.rb:22:in `call'
rack (1.4.1) lib/rack/methodoverride.rb:21:in `call'
rack (1.4.1) lib/rack/runtime.rb:17:in `call'
activesupport (3.2.2) lib/active_support/cache/strategy/local_cache.rb:72:in `call'
rack (1.4.1) lib/rack/lock.rb:15:in `call'
rack-cache (1.2) lib/rack/cache/context.rb:136:in `forward'
rack-cache (1.2) lib/rack/cache/context.rb:245:in `fetch'
rack-cache (1.2) lib/rack/cache/context.rb:185:in `lookup'
rack-cache (1.2) lib/rack/cache/context.rb:66:in `call!'
rack-cache (1.2) lib/rack/cache/context.rb:51:in `call'
railties (3.2.2) lib/rails/engine.rb:479:in `call'
railties (3.2.2) lib/rails/application.rb:220:in `call'
railties (3.2.2) lib/rails/railtie/configurable.rb:30:in `method_missing'
/home/rails/.rvm/gems/ruby-1.9.2-p318/gems/passenger-3.0.11/lib/phusion_passenger/rack/request_handler.rb:96:in `process_request'
/home/rails/.rvm/gems/ruby-1.9.2-p318/gems/passenger-3.0.11/lib/phusion_passenger/abstract_request_handler.rb:513:in `accept_and_process_next_request'
/home/rails/.rvm/gems/ruby-1.9.2-p318/gems/passenger-3.0.11/lib/phusion_passenger/abstract_request_handler.rb:274:in `main_loop'
/home/rails/.rvm/gems/ruby-1.9.2-p318/gems/passenger-3.0.11/lib/phusion_passenger/rack/application_spawner.rb:206:in `start_request_handler'
/home/rails/.rvm/gems/ruby-1.9.2-p318/gems/passenger-3.0.11/lib/phusion_passenger/rack/application_spawner.rb:171:in `block in handle_spawn_application'
/home/rails/.rvm/gems/ruby-1.9.2-p318/gems/passenger-3.0.11/lib/phusion_passenger/utils.rb:479:in `safe_fork'
/home/rails/.rvm/gems/ruby-1.9.2-p318/gems/passenger-3.0.11/lib/phusion_passenger/rack/application_spawner.rb:166:in `handle_spawn_application'
/home/rails/.rvm/gems/ruby-1.9.2-p318/gems/passenger-3.0.11/lib/phusion_passenger/abstract_server.rb:357:in `server_main_loop'
/home/rails/.rvm/gems/ruby-1.9.2-p318/gems/passenger-3.0.11/lib/phusion_passenger/abstract_server.rb:206:in `start_synchronously'
/home/rails/.rvm/gems/ruby-1.9.2-p318/gems/passenger-3.0.11/lib/phusion_passenger/abstract_server.rb:180:in `start'
/home/rails/.rvm/gems/ruby-1.9.2-p318/gems/passenger-3.0.11/lib/phusion_passenger/rack/application_spawner.rb:129:in `start'
/home/rails/.rvm/gems/ruby-1.9.2-p318/gems/passenger-3.0.11/lib/phusion_passenger/spawn_manager.rb:253:in `block (2 levels) in spawn_rack_application'
/home/rails/.rvm/gems/ruby-1.9.2-p318/gems/passenger-3.0.11/lib/phusion_passenger/abstract_server_collection.rb:132:in `lookup_or_add'
/home/rails/.rvm/gems/ruby-1.9.2-p318/gems/passenger-3.0.11/lib/phusion_passenger/spawn_manager.rb:246:in `block in spawn_rack_application'
/home/rails/.rvm/gems/ruby-1.9.2-p318/gems/passenger-3.0.11/lib/phusion_passenger/abstract_server_collection.rb:82:in `block in synchronize'
<internal:prelude>:10:in `synchronize'
/home/rails/.rvm/gems/ruby-1.9.2-p318/gems/passenger-3.0.11/lib/phusion_passenger/abstract_server_collection.rb:79:in `synchronize'
/home/rails/.rvm/gems/ruby-1.9.2-p318/gems/passenger-3.0.11/lib/phusion_passenger/spawn_manager.rb:244:in `spawn_rack_application'
/home/rails/.rvm/gems/ruby-1.9.2-p318/gems/passenger-3.0.11/lib/phusion_passenger/spawn_manager.rb:137:in `spawn_application'
/home/rails/.rvm/gems/ruby-1.9.2-p318/gems/passenger-3.0.11/lib/phusion_passenger/spawn_manager.rb:275:in `handle_spawn_application'
/home/rails/.rvm/gems/ruby-1.9.2-p318/gems/passenger-3.0.11/lib/phusion_passenger/abstract_server.rb:357:in `server_main_loop'
/home/rails/.rvm/gems/ruby-1.9.2-p318/gems/passenger-3.0.11/lib/phusion_passenger/abstract_server.rb:206:in `start_synchronously'
/home/rails/.rvm/gems/ruby-1.9.2-p318/gems/passenger-3.0.11/helper-scripts/passenger-spawn-server:99:in `<main>'
Aren't you configured session_id in config.log_tags? If so, removing it may help.

Severe Errors in Solr

I've been trying to get sunspot/solr working in a new environment (Ubuntu), and I'm getting this error of 'Severe Errors in Solr' which I've included below.
I don't know what is causing the error, and the error recommends changing the setting
< abortOnConfigurationError >false</abortOnConfigurationError>
I tried that, though because I'm using rails and sunspot, my value looked like
${solr.abortOnConfigurationError:true}
Either way, I don't think just ignoring the error is the best thing to do. I can't seem to find anything in my web error logs related to this issue.
Is there a way to just blow-away all the solr files, and just start from scratch? Seeing as it needs to index regularly any way, is there a reason why I shouldn't do this? Any other suggestions?
As requested,here is the full stack trace
rsolr (1.0.2) lib/rsolr/client.rb:211:in `adapt_response'
rsolr (1.0.2) lib/rsolr/client.rb:154:in `execute'
rsolr (1.0.2) lib/rsolr/client.rb:148:in `send_and_receive'
(eval):2:in `post'
sunspot (1.3.0.rc6) lib/sunspot/search/abstract_search.rb:38:in `execute'
sunspot_rails (1.3.0.rc6) lib/sunspot/rails/searchable.rb:329:in `solr_execute_search'
sunspot_rails (1.3.0.rc6) lib/sunspot/rails/searchable.rb:153:in `solr_search'
app/controllers/food_names_controller.rb:6:in `index'
actionpack (3.0.0) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
actionpack (3.0.0) lib/abstract_controller/base.rb:150:in `process_action'
actionpack (3.0.0) lib/action_controller/metal/rendering.rb:11:in `process_action'
actionpack (3.0.0) lib/abstract_controller/callbacks.rb:18:in `block in process_action'
activesupport (3.0.0) lib/active_support/callbacks.rb:445:in `_run__313220073__process_action__135895317__callbacks'
activesupport (3.0.0) lib/active_support/callbacks.rb:409:in `_run_process_action_callbacks'
activesupport (3.0.0) lib/active_support/callbacks.rb:93:in `run_callbacks'
actionpack (3.0.0) lib/abstract_controller/callbacks.rb:17:in `process_action'
actionpack (3.0.0) lib/action_controller/metal/instrumentation.rb:30:in `block in process_action'
activesupport (3.0.0) lib/active_support/notifications.rb:52:in `block in instrument'
activesupport (3.0.0) lib/active_support/notifications/instrumenter.rb:21:in `instrument'
activesupport (3.0.0) lib/active_support/notifications.rb:52:in `instrument'
actionpack (3.0.0) lib/action_controller/metal/instrumentation.rb:29:in `process_action'
actionpack (3.0.0) lib/action_controller/metal/rescue.rb:17:in `process_action'
actionpack (3.0.0) lib/abstract_controller/base.rb:119:in `process'
actionpack (3.0.0) lib/abstract_controller/rendering.rb:40:in `process'
actionpack (3.0.0) lib/action_controller/metal.rb:133:in `dispatch'
actionpack (3.0.0) lib/action_controller/metal/rack_delegation.rb:14:in `dispatch'
actionpack (3.0.0) lib/action_controller/metal.rb:173:in `block in action'
actionpack (3.0.0) lib/action_dispatch/routing/route_set.rb:62:in `call'
actionpack (3.0.0) lib/action_dispatch/routing/route_set.rb:62:in `dispatch'
actionpack (3.0.0) lib/action_dispatch/routing/route_set.rb:27:in `call'
rack-mount (0.6.14) lib/rack/mount/route_set.rb:148:in `block in call'
rack-mount (0.6.14) lib/rack/mount/code_generation.rb:93:in `block in recognize'
rack-mount (0.6.14) lib/rack/mount/code_generation.rb:68:in `optimized_each'
rack-mount (0.6.14) lib/rack/mount/code_generation.rb:92:in `recognize'
rack-mount (0.6.14) lib/rack/mount/route_set.rb:139:in `call'
actionpack (3.0.0) lib/action_dispatch/routing/route_set.rb:492:in `call'
actionpack (3.0.0) lib/action_dispatch/middleware/best_standards_support.rb:17:in `call'
actionpack (3.0.0) lib/action_dispatch/middleware/head.rb:14:in `call'
rack (1.2.4) lib/rack/methodoverride.rb:24:in `call'
actionpack (3.0.0) lib/action_dispatch/middleware/params_parser.rb:21:in `call'
actionpack (3.0.0) lib/action_dispatch/middleware/flash.rb:182:in `call'
actionpack (3.0.0) lib/action_dispatch/middleware/session/abstract_store.rb:149:in `call'
actionpack (3.0.0) lib/action_dispatch/middleware/cookies.rb:287:in `call'
activerecord (3.0.0) lib/active_record/query_cache.rb:32:in `block in call'
activerecord (3.0.0) lib/active_record/connection_adapters/abstract/query_cache.rb:28:in `cache'
activerecord (3.0.0) lib/active_record/query_cache.rb:12:in `cache'
activerecord (3.0.0) lib/active_record/query_cache.rb:31:in `call'
activerecord (3.0.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:355:in `call'
actionpack (3.0.0) lib/action_dispatch/middleware/callbacks.rb:46:in `block in call'
activesupport (3.0.0) lib/active_support/callbacks.rb:415:in `_run_call_callbacks'
actionpack (3.0.0) lib/action_dispatch/middleware/callbacks.rb:44:in `call'
rack (1.2.4) lib/rack/sendfile.rb:106:in `call'
actionpack (3.0.0) lib/action_dispatch/middleware/remote_ip.rb:48:in `call'
actionpack (3.0.0) lib/action_dispatch/middleware/show_exceptions.rb:46:in `call'
railties (3.0.0) lib/rails/rack/logger.rb:13:in `call'
rack (1.2.4) lib/rack/runtime.rb:17:in `call'
activesupport (3.0.0) lib/active_support/cache/strategy/local_cache.rb:72:in `call'
rack (1.2.4) lib/rack/lock.rb:11:in `block in call'
<internal:prelude>:10:in `synchronize'
rack (1.2.4) lib/rack/lock.rb:11:in `call'
actionpack (3.0.0) lib/action_dispatch/middleware/static.rb:30:in `call'
railties (3.0.0) lib/rails/application.rb:168:in `call'
railties (3.0.0) lib/rails/application.rb:77:in `method_missing'
railties (3.0.0) lib/rails/rack/log_tailer.rb:14:in `call'
rack (1.2.4) lib/rack/content_length.rb:13:in `call'
rack (1.2.4) lib/rack/chunked.rb:15:in `call'
thin (1.2.11) lib/thin/connection.rb:84:in `block in pre_process'
thin (1.2.11) lib/thin/connection.rb:82:in `catch'
thin (1.2.11) lib/thin/connection.rb:82:in `pre_process'
thin (1.2.11) lib/thin/connection.rb:57:in `process'
thin (1.2.11) lib/thin/connection.rb:42:in `receive_data'
eventmachine (0.12.10) lib/eventmachine.rb:256:in `run_machine'
eventmachine (0.12.10) lib/eventmachine.rb:256:in `run'
thin (1.2.11) lib/thin/backends/base.rb:61:in `start'
thin (1.2.11) lib/thin/server.rb:159:in `start'
rack (1.2.4) lib/rack/handler/thin.rb:14:in `run'
rack (1.2.4) lib/rack/server.rb:217:in `start'
railties (3.0.0) lib/rails/commands/server.rb:65:in `start'
railties (3.0.0) lib/rails/commands.rb:30:in `block in <top (required)>'
railties (3.0.0) lib/rails/commands.rb:27:in `tap'
railties (3.0.0) lib/rails/commands.rb:27:in `<top (required)>'
script/rails:6:in `require'
script/rails:6:in `<main>'