undefined method `each' for String when using https - ruby

In my application staging environment there is an error when I try to access a page over https, the webpage is correctly working with http. The error I get is :
undefined method `each' for #<String:0x00000009371f28>
The place where it fails is on in th gem rack on the line:
body.each { |part| parts << part }
in
def digest_body(body)
parts = []
body.each { |part| parts << part }
string_body = parts.join
digest = Digest::MD5.hexdigest(string_body) unless string_body.empty?
[digest, parts]
end
It seems that he can't handle the body that is passed. I inspected the body and it is a string with all the html code of my page in it. The data type of this parameter should be an array.
"<!DOCTYPE html>\n<html class='no-js' lang='fr' xml:lang='fr'>\n<head>\n<meta charset='utf-8'>\n<meta content='IE=edge,chrome=1' http-equiv='X-UA-Compatible'>\n<meta content='width=device-width' name='viewport'>\n<title>Bienvenue sur Zurban Culture | Admin Panel | Zurban Culture</title>\n<meta content=\"authenticity_token\" name=\"csrf-param\" />\n<meta content=\"fEVrJPyUwdf4FZ2GSWW/p01SrByXlJpq+xSbAXOkxBg=\" name=\"csrf-token\" />\n<!--[if lt IE 9]>\n<script src='http://html5shim.googlecode.com/svn/trunk/html5.js' type='text/javascript'></script>\n<![endif]-->\n<script src=\"https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js\" type=\"text/javascript\"></script>\n<link href=\"/assets/admin/admin-6033541466a41863e188a9fa9e0ea9bd.css\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\" />\n<link href=\"/assets/admin/print-088f5bc50dba980c42676157c724ed0a.css\" media=\"print\" rel=\"stylesheet\" type=\"text/css\" />\n\n<script src='https://www.google.com/jsapi' type='text/javascript'></script>\n\n<link href='/favicon.ico' rel='shortcut icon'>\n</head>\n<body data-offset='50' data-spy='scroll' id='admin_show'>\n<h1 class='hidden print'>\nZurban Culture\n</h1>\n<div class='navbar navbar-fixed-top noPrint'>\n<div class='navbar-inner'>\n<div class='container-fluid'>\n<a class='btn btn-navbar' data-target='.nav-collapse' data-toggle='collapse'>\n<span class='icon-bar'></span>\n<span class='icon-bar'></span>\n<span class='icon-bar'></span>\n</a>\n<a class='brand' href='/admin'>Zurban Culture</a>\n<div class='nav-collapse'>\n<ul class='nav' id='tabbedInterface'>\n<li class=\"dropdown\">Produits<b class=\"caret\"></b><ul class='dropdown-menu'>\n<li>Tous produits (4064)</li>\n<li>Brouillons (156)</li>\n<li>Effacés (274)</li>\n<li>Bons</li>\n<li>Familles (24)</li>\n<li>Maintenance</li>\n</ul>\n</li><li class=\"brands_tab\">Marques</li>\n<li class=\"dropdown\">Ventes & Marketing<b class=\"caret\"></b><ul class='dropdown-menu'>\n<li>En vente (3905)</li>\n<li>Brouillons (142)</li>\n<li>Planning (0)</li>\n<li><span class=\"translation_missing\" title=\"translation missing: fr.admin.menu.sales.planned\">Planned</span></li>\n<li>Codes promotionnels (27)</li>\n<li>Page d'accueil</li>\n<li>Collections</li>\n<li>Chèques cadeaux</li>\n<li>Chèques</li>\n</ul>\n</li><li class=\"dropdown\">Commandes<b class=\"caret\"></b><ul class='dropdown-menu'>\n<li>En attente (0)</li>\n<li>A vérifier (3)</li>\n<li>Payées (7)</li>\n<li>Traitement (0)</li>\n<li>Envoyées (307)</li>\n<li>Complètée (9205)</li>\n<li>Indisponible (1)</li>\n<li>Annulées (8736)</li>\n<li>Fraudes (12)</li>\n<li>Tentatives de paiements</li>\n</ul>\n</li><li class=\"dropdown\">Retours<b class=\"caret\"></b><ul class='dropdown-menu'>\n<li>En attente (77)</li>\n<li>Réceptionné (23)</li>\n<li>Remboursé (1115)</li>\n<li>Procédure annulée (4)</li>\n</ul>\n</li><li class=\"dropdown\">Avis <b class=\"caret\"></b><ul class='dropdown-menu'>\n<li>À approuver (0)</li>\n<li>Approuvés (3)</li>\n<li>Refusés (0)</li>\n<li>Effacés (0)</li>\n</ul>\n</li><li class=\"dropdown\">Utilisateurs<b class=\"caret\"></b><ul class='dropdown-menu'>\n<li>Utilisateurs</li>\n<li>Utilisateurs effacés</li>\n<li>Invitations</li>\n</ul>\n</li><li class=\"help_sections_tab\">Sections d'aide</li>\n<li class=\"dropdown\"><img alt=\"Icon_stats\" src=\"/assets/admin/icon_stats-3905dbfb6e4ba900e54d7c49d67f5c49.png\" /><b class=\"caret\"></b><ul class='dropdown-menu'>\n<li>\n<span class=\"translation_missing\" title=\"translation missing: fr.admin.submenu.overview\">Overview</span>\n</li>\n<li>\n<span class=\"translation_missing\" title=\"translation missing: fr.admin.submenu.products\">Products</span>\n</li>\n<li>\n<span class=\"translation_missing\" title=\"translation missing: fr.admin.submenu.orders\">Orders</span>\n</li>\n<li>\n<span class=\"translation_missing\" title=\"translation missing: fr.admin.submenu.returns\">Returns</span>\n</li>\n<li>\n<span class=\"translation_missing\" title=\"translation missing: fr.admin.submenu.users\">Users</span>\n</li>\n<li>\n<span class=\"translation_missing\" title=\"translation missing: fr.admin.submenu.sales_report\">Sales Report</span>\n</li>\n<li>\n<span class=\"translation_missing\" title=\"translation missing: fr.admin.submenu.stock_report\">Stock Report</span>\n</li>\n<li>\n<span class=\"translation_missing\" title=\"translation missing: fr.admin.submenu.purchase_report\">Purchase Report</span>\n</li>\n<li>\n<span class=\"translation_missing\" title=\"translation missing: fr.admin.submenu.sales_history\">Sales History</span>\n</li>\n<li>\n<span class=\"translation_missing\" title=\"translation missing: fr.admin.submenu.favorites\">Favorites</span>\n</li>\n</ul>\n</li></ul>\n\n<ul class='nav pull-right'>\n<li class='searchbox'>\n<form accept-charset=\"UTF-8\" action=\"/admin/search\" class=\"navbar-search pull-right\" method=\"get\"><div style=\"margin:0;padding:0;display:inline\"><input name=\"utf8\" type=\"hidden\" value=\"✓\" /></div>\n<input class=\"search-query span2\" id=\"query\" name=\"query\" size=\"20\" type=\"text\" value=\"Rechercher\" />\n\n</form>\n\n</li>\n<li class='dropdown'>\n<a class='dropdown-toggle' data-toggle='dropdown' href='#'>\n<i class='icon-user icon-white'></i>\n</a>\n<ul class='dropdown-menu'>\n<li>\nZurban Culture\n</li>\n<li>\nDéconnexion\n</li>\n</ul>\n</li>\n</ul>\n\n</div>\n</div>\n</div>\n</div>\n<div class='container-fluid noPrint'>\n<div class='subnav'>\n<ul class='nav nav-pills'>\n<li class=\"active\">Statistique rapides</li>\n<li>Logs</li>\n</ul>\n\n</div>\n<div class='notices_wrapper noPrint'>\n<div class='row-fluid'>\n<div class='span12'>\n\n</div>\n</div>\n</div>\n</div>\n<div class='container-fluid'>\n<div class='row-fluid'>\n<div class='span12'>\n<div class=\"page-header\">\n <h1>Bienvenue sur Zurban Culture</h1> \n</div>\n\n\n <form accept-charset=\"UTF-8\" action=\"https://beta.jeansattitude.fr/admin\" class=\"well\" method=\"get\"><div style=\"margin:0;padding:0;display:inline\"><input name=\"utf8\" type=\"hidden\" value=\"✓\" /></div>\n <input class=\"datepicker onChangeSubmit\" id=\"start_date\" length=\"8\" name=\"start_date\" placeholder=\"Start Date\" type=\"text\" value=\"2013-04-01\" />\n <input class=\"datepicker onChangeSubmit\" id=\"end_date\" length=\"8\" name=\"end_date\" placeholder=\"End Date\" type=\"text\" value=\"2013-04-23\" />\n <input type=\"submit\" class=\"btn\">\n </form>\n <div class=\"row-fluid\">\n <div class=\"section dashboard span6\" id=\"orders_section\">\n <div class=\"well\">\n <h2 class=\"sectionHeader\">Montant des ventes cumulés</h2>\n <div id=\"ordersChart\" class=\"graph\" style=\"width: 95%; height: 300px; margin: 0; padding: 0\"></div>\n </div>\n </div>\n <div class=\"section dashboard span6\" id=\"revenue_section\">\n <div class=\"well\">\n <h2 class=\"sectionHeader\">Montant des ventes</h2>\n <div id=\"revenueChart\" class=\"graph\" style=\"width: 95%; height: 300px; margin: 0; padding: 0\"></div>\n </div>\n </div>\n </div>\n\n <div class=\"row-fluid\">\n <div class=\"section dashboard span6\" id=\"orders_shipped_section\">\n <div class=\"well\">\n <h2 class=\"sectionHeader\">Commandes Expédiées</h2>\n <div id=\"shippedOrdersChart\" class=\"graph\" style=\"width: 95%; height: 300px; margin: 0; padding: 0\"></div>\n </div>\n </div>\n\n <div class=\"section dashboard span6\" id=\"users_section\">\n <div class=\"well\">\n <h2 class=\"sectionHeader\">Nouveaux utilisateurs confirmés</h2>\n <div id=\"usersChart\" class=\"graph\" style=\"width: 95%; height: 300px; margin: 0; padding: 0\"></div>\n </div>\n </div>\n </div>\n\n\n <div id=\"revenueChart\"></div>\n<script type=\"text/javascript\" src=\"http://www.google.com/jsapi\"></script>\n<script type=\"text/javascript\">\nvar rgviz_revenueChart = null;\nvar rgviz_revenueChart_data = null;\nfunction rgviz_draw_revenueChart() {\n var query = new google.visualization.Query('http://stats.zurbanculture.fr/orders/datasource');\n var q = 'select toDate(`paid_at`), `old_members`, `new_members` where ((`state` = \"paid\" or `state` = \"processing\" or `state` = \"shipped\" or `state` = \"completed\") and `paid_at` >= \"2013-04-01\" and `paid_at` <= \"2013-04-24\") group by toDate(`paid_at`) order by toDate(`paid_at`) asc label toDate(`paid_at`) \\'Date\\', `old_members` \\'Ventes Anciens Utilisateurs\\', `new_members` \\'Ventes Nouveaux Utilisateurs\\'';\n query.setQuery(q);\n query.send(function(response) {\n rgviz_revenueChart = new google.visualization.ColumnChart(document.getElementById('revenueChart'));\n rgviz_revenueChart_data = response.getDataTable();\n rgviz_revenueChart_options = {\"is3D\":true,\"width\":\"100%\",\"height\":\"80%\",\"legend\":{\"position\":\"bottom\",\"textStyle\":{\"fontSize\":12}},\"chartArea\":{\"left\":70,\"top\":30,\"width\":\"85%\",\"height\":\"75%\"},\"isStacked\":true};\n rgviz_revenueChart.draw(rgviz_revenueChart_data, rgviz_revenueChart_options);\n});\n}\ngoogle.load(\"visualization\", \"1\", {'packages':['corechart']});\ngoogle.setOnLoadCallback(rgviz_draw_revenueChart);\n</script>\n\n\n <div id=\"ordersChart\"></div>\n<script type=\"text/javascript\">\nvar rgviz_ordersChart = null;\nvar rgviz_ordersChart_data = null;\nfunction rgviz_draw_ordersChart() {\n var query = new google.visualization.Query('http://stats.zurbanculture.fr/orders/datasource');\n var q = 'select toDate(`paid_at`), sum(`total`) where ((`state` = \"paid\" or `state` = \"processing\" or `state` = \"shipped\" or `state` = \"completed\") and `paid_at` >= \"2013-04-01\" and `paid_at` <= \"2013-04-24\") group by toDate(`paid_at`) order by toDate(`paid_at`) asc label toDate(`paid_at`) \\'Date\\', sum(`total`) \\'Montant Ventes\\'';\n query.setQuery(q);\n query.send(function(response) {\n rgviz_ordersChart = new google.visualization.ColumnChart(document.getElementById('ordersChart'));\n rgviz_ordersChart_data = response.getDataTable();\n rgviz_ordersChart_options = {\"is3D\":true,\"width\":\"100%\",\"height\":\"80%\",\"legend\":\"none\",\"chartArea\":{\"left\":70,\"top\":30,\"width\":\"85%\",\"height\":\"75%\"}};\n rgviz_ordersChart.draw(rgviz_ordersChart_data, rgviz_ordersChart_options);\n});\n}\ngoogle.setOnLoadCallback(rgviz_draw_ordersChart);\n</script>\n\n <div id=\"shippedOrdersChart\"></div>\n<script type=\"text/javascript\">\nvar rgviz_shippedOrdersChart = null;\nvar rgviz_shippedOrdersChart_data = null;\nfunction rgviz_draw_shippedOrdersChart() {\n var query = new google.visualization.Query('http://stats.zurbanculture.fr/orders/datasource');\n var q = 'select toDate(`shipped_at`), count(`id`) where ((`state` = \"paid\" or `state` = \"processing\" or `state` = \"shipped\" or `state` = \"completed\") and `shipped_at` >= \"2013-04-01\" and `paid_at` <= \"2013-04-24\") group by toDate(`shipped_at`) order by toDate(`shipped_at`) asc label toDate(`shipped_at`) \\'Date\\', count(`id`) \\'Commandes Expédiées\\'';\n query.setQuery(q);\n query.send(function(response) {\n rgviz_shippedOrdersChart = new google.visualization.AreaChart(document.getElementById('shippedOrdersChart'));\n rgviz_shippedOrdersChart_data = response.getDataTable();\n rgviz_shippedOrdersChart_options = {\"is3D\":true,\"width\":\"100%\",\"height\":\"80%\",\"legend\":\"none\",\"chartArea\":{\"left\":70,\"top\":30,\"width\":\"85%\",\"height\":\"75%\"}};\n rgviz_shippedOrdersChart.draw(rgviz_shippedOrdersChart_data, rgviz_shippedOrdersChart_options);\n});\n}\ngoogle.setOnLoadCallback(rgviz_draw_shippedOrdersChart);\n</script>\n\n <div id=\"usersChart\"></div>\n<script type=\"text/javascript\">\nvar rgviz_usersChart = null;\nvar rgviz_usersChart_data = null;\nfunction rgviz_draw_usersChart() {\n var query = new google.visualization.Query('http://stats.zurbanculture.fr/users/datasource');\n var q = 'select concat(month(`created_at`), \" \", year(`created_at`)), `seo`, `organique` where (`created_at` >= \"2012-04-23\" and `created_at` <= \"2013-04-24\" and `confirmed` = 1) group by concat(month(`created_at`), \" \", year(`created_at`)) order by `created_at` asc label concat(month(`created_at`), \" \", year(`created_at`)) \\'Month\\', `seo` \\'SEO\\', `organique` \\'Organique\\'';\n query.setQuery(q);\n query.send(function(response) {\n rgviz_usersChart = new google.visualization.LineChart(document.getElementById('usersChart'));\n rgviz_usersChart_data = response.getDataTable();\n rgviz_usersChart_options = {\"is3D\":true,\"width\":\"100%\",\"height\":\"80%\",\"legend\":{\"position\":\"bottom\",\"textStyle\":{\"fontSize\":12}},\"chartArea\":{\"left\":70,\"top\":30,\"width\":\"85%\",\"height\":\"75%\"}};\n rgviz_usersChart.draw(rgviz_usersChart_data, rgviz_usersChart_options);\n});\n}\ngoogle.setOnLoadCallback(rgviz_draw_usersChart);\n</script>\n\n\n</div>\n</div>\n<footer class='footer'>\n<p>Zurban Culture v2.0 - Rails 3.2.13 (staging) / Ruby 1.9.3 patchlevel 327 2012-11-10 - /srv/www/jeansattitude/releases/20130423082652</p>\n</footer>\n</div>\n<script src=\"/assets/admin-ac2e83dde06736c3279cc5c973afd46a.js\" type=\"text/javascript\"></script>\n\n</body>\n</html>\n"
Someone has an idea why the request fails and the body is not containing and array like it needs to be? Here you see my traceroute, it isn't clear for me what cause the problem because I don't see any trace of my application in it and I don't pass anything to this function from my application.
NoMethodError (undefined method `each' for #<String:0x00000009371f28>):
rack (1.4.5) lib/rack/etag.rb:59:in `digest_body'
rack (1.4.5) lib/rack/etag.rb:26:in `call'
rack (1.4.5) lib/rack/conditionalget.rb:25:in `call'
actionpack (3.2.13) lib/action_dispatch/middleware/head.rb:14:in `call'
actionpack (3.2.13) lib/action_dispatch/middleware/params_parser.rb:21:in `call'
actionpack (3.2.13) lib/action_dispatch/middleware/flash.rb:242:in `call'
rack (1.4.5) lib/rack/session/abstract/id.rb:210:in `context'
rack (1.4.5) lib/rack/session/abstract/id.rb:205:in `call'
actionpack (3.2.13) lib/action_dispatch/middleware/cookies.rb:341:in `call'
activerecord (3.2.13) lib/active_record/query_cache.rb:64:in `call'
activerecord (3.2.13) lib/active_record/connection_adapters/abstract/connection_pool.rb:479:in `call'
actionpack (3.2.13) lib/action_dispatch/middleware/callbacks.rb:28:in `block in call'
activesupport (3.2.13) lib/active_support/callbacks.rb:405:in `_run__965187821369700966__call__4271865895200548975__callbacks'
activesupport (3.2.13) lib/active_support/callbacks.rb:405:in `__run_callback'
activesupport (3.2.13) lib/active_support/callbacks.rb:385:in `_run_call_callbacks'
activesupport (3.2.13) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (3.2.13) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (3.2.13) lib/action_dispatch/middleware/remote_ip.rb:31:in `call'
airbrake (3.1.11) lib/airbrake/rails/middleware.rb:13:in `call'
actionpack (3.2.13) lib/action_dispatch/middleware/debug_exceptions.rb:16:in `call'
actionpack (3.2.13) lib/action_dispatch/middleware/show_exceptions.rb:56:in `call'
railties (3.2.13) lib/rails/rack/logger.rb:32:in `call_app'
railties (3.2.13) lib/rails/rack/logger.rb:16:in `block in call'
activesupport (3.2.13) lib/active_support/tagged_logging.rb:22:in `tagged'
railties (3.2.13) lib/rails/rack/logger.rb:16:in `call'
actionpack (3.2.13) lib/action_dispatch/middleware/request_id.rb:22:in `call'
rack (1.4.5) lib/rack/methodoverride.rb:21:in `call'
rack (1.4.5) lib/rack/runtime.rb:17:in `call'
activesupport (3.2.13) lib/active_support/cache/strategy/local_cache.rb:72:in `call'
rack (1.4.5) lib/rack/lock.rb:15:in `call'
actionpack (3.2.13) lib/action_dispatch/middleware/static.rb:63: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'
airbrake (3.1.11) lib/airbrake/user_informer.rb:16:in `_call'
airbrake (3.1.11) lib/airbrake/user_informer.rb:12:in `call'
railties (3.2.13) lib/rails/engine.rb:479:in `call'
railties (3.2.13) lib/rails/application.rb:223:in `call'
railties (3.2.13) lib/rails/railtie/configurable.rb:30:in `method_missing'
passenger (3.0.19) lib/phusion_passenger/rack/request_handler.rb:96:in `process_request'
passenger (3.0.19) lib/phusion_passenger/abstract_request_handler.rb:516:in `accept_and_process_next_request'
passenger (3.0.19) lib/phusion_passenger/abstract_request_handler.rb:274:in `main_loop'
passenger (3.0.19) lib/phusion_passenger/rack/application_spawner.rb:206:in `start_request_handler'
passenger (3.0.19) lib/phusion_passenger/rack/application_spawner.rb:171:in `block in handle_spawn_application'
passenger (3.0.19) lib/phusion_passenger/utils.rb:470:in `safe_fork'
passenger (3.0.19) lib/phusion_passenger/rack/application_spawner.rb:166:in `handle_spawn_application'
passenger (3.0.19) lib/phusion_passenger/abstract_server.rb:357:in `server_main_loop'
passenger (3.0.19) lib/phusion_passenger/abstract_server.rb:206:in `start_synchronously'
passenger (3.0.19) lib/phusion_passenger/abstract_server.rb:180:in `start'
passenger (3.0.19) lib/phusion_passenger/rack/application_spawner.rb:129:in `start'
passenger (3.0.19) lib/phusion_passenger/spawn_manager.rb:253:in `block (2 levels) in spawn_rack_application'
passenger (3.0.19) lib/phusion_passenger/abstract_server_collection.rb:132:in `lookup_or_add'
passenger (3.0.19) lib/phusion_passenger/spawn_manager.rb:246:in `block in spawn_rack_application'
passenger (3.0.19) lib/phusion_passenger/abstract_server_collection.rb:82:in `block in synchronize'
<internal:prelude>:10:in `synchronize'
passenger (3.0.19) lib/phusion_passenger/abstract_server_collection.rb:79:in `synchronize'
passenger (3.0.19) lib/phusion_passenger/spawn_manager.rb:244:in `spawn_rack_application'
passenger (3.0.19) lib/phusion_passenger/spawn_manager.rb:137:in `spawn_application'
passenger (3.0.19) lib/phusion_passenger/spawn_manager.rb:275:in `handle_spawn_application'
passenger (3.0.19) lib/phusion_passenger/abstract_server.rb:357:in `server_main_loop'
passenger (3.0.19) lib/phusion_passenger/abstract_server.rb:206:in `start_synchronously'
passenger (3.0.19) helper-scripts/passenger-spawn-server:99:in `<main>'
See also my issue I opened on the rack gem, but it seems not a issue from them. https://github.com/rack/rack/issues/548
SOLUTION:
This happened because of a custom middleware that was returning the body as a string, I wrapped this body in an array and problem was solved! Thanks for the help!

You say:
I inspected the body and it is a string with all the html code of my page in it. The data type of this parameter should be an array.
Where is the body parameter coming from? What do you expect the elements of this array to be? It seems like this may be what you want:
def digest_body(body)
parts = body.split("\n")
string_body = parts.join
digest = Digest::MD5.hexdigest(string_body) unless string_body.empty?
[digest, parts]
end

Related

Getting TypeError - can't clone Symbol: error when using active_model_serializer

So I have Ruby 2.1.3 with Rails 4.2.0 and I am using the active_model_serializer gem to send proper json data to AngularJs.
Not I only upgraded today from Rails 4.1.6 to 4.2.0. With the previous version the problem did not exist.
The problem appears when I try to get json from my medium show action:
def show
medium = Medium.find(params[:id])
respond_with medium, include: [{comments: :user}, :likes, :user]
end
And this is how the same action looked before I upgraded rails:
def show
medium = Medium.includes([{comments: :user}, :likes, :user]).find(params[:id])
respond_with medium
end
It used to be able to work the old way but with the new rails, it does not have the included ActiveModels with the medium anymore in the sent json data.
So I changed the code using the examples on this page: https://github.com/rails-api/active_model_serializers
Here is how my media serializer looks like:
class MediumSerializer < ActiveModel::Serializer
attributes :id,
:text,
:image_video_file_name,
:image_video_croppable_url,
:image_video_thumb_url,
:image_video_big_url
has_one :user
has_many :comments, :likes
end
Before the upgrade it looked like this:
class MediumSerializer < ActiveModel::Serializer
attributes :id,
:text,
:image_video_file_name,
:image_video_croppable_url,
:image_video_thumb_url,
:image_video_big_url
has_one :user
has_many :comments, :likes
def include_user?
object.association(:user).loaded?
end
def include_comments?
object.association(:comments).loaded?
end
def include_associations?
object.association(:user, :comments, :likes).loaded?
end
end
So, when making a query for that show action, the error that my Rails application throws is this:
Started GET "/media/7.json" for 127.0.0.1 at 2014-12-25 18:13:43 +0200
Processing by Content::MediaController#show as JSON
Parameters: {"id"=>"7"}
Medium Load (0.4ms) SELECT "media".* FROM "media" WHERE "media"."id" = $1 LIMIT 1 [["id", 7]]
Comment Load (0.5ms) SELECT "comments".* FROM "comments" WHERE "comments"."medium_id" = $1 [["medium_id", 7]]
Completed 500 Internal Server Error in 59ms
TypeError - can't clone Symbol:
activesupport (4.2.0) lib/active_support/core_ext/object/try.rb:77:in `try!'
activesupport (4.2.0) lib/active_support/core_ext/object/try.rb:63:in `try'
activerecord (4.2.0) lib/active_record/serialization.rb:12:in `serializable_hash'
activemodel (4.2.0) lib/active_model/serialization.rb:114:in `block (2 levels) in serializable_hash'
activemodel (4.2.0) lib/active_model/serialization.rb:114:in `block in serializable_hash'
activemodel (4.2.0) lib/active_model/serialization.rb:158:in `block in serializable_add_includes'
activemodel (4.2.0) lib/active_model/serialization.rb:156:in `serializable_add_includes'
activemodel (4.2.0) lib/active_model/serialization.rb:112:in `serializable_hash'
activerecord (4.2.0) lib/active_record/serialization.rb:17:in `serializable_hash'
activemodel (4.2.0) lib/active_model/serializers/json.rb:99:in `as_json'
app/models/medium.rb:32:in `as_json'
activesupport (4.2.0) lib/active_support/json/encoding.rb:34:in `encode'
activesupport (4.2.0) lib/active_support/json/encoding.rb:21:in `encode'
activesupport (4.2.0) lib/active_support/core_ext/object/json.rb:37:in `to_json_with_active_support_encoder'
actionpack (4.2.0) lib/action_controller/metal/renderers.rb:116:in `block in <module:Renderers>'
actionpack (4.2.0) lib/action_controller/metal/renderers.rb:45:in `block in _render_to_body_with_renderer'
/home/kaspar/.rbenv/versions/2.1.3/lib/ruby/2.1.0/set.rb:263:in `each'
actionpack (4.2.0) lib/action_controller/metal/renderers.rb:41:in `_render_to_body_with_renderer'
actionpack (4.2.0) lib/action_controller/metal/renderers.rb:37:in `render_to_body'
actionpack (4.2.0) lib/abstract_controller/rendering.rb:25:in `render'
actionpack (4.2.0) lib/action_controller/metal/rendering.rb:16:in `render'
actionpack (4.2.0) lib/action_controller/metal/instrumentation.rb:41:in `block (2 levels) in render'
activesupport (4.2.0) lib/active_support/core_ext/benchmark.rb:12:in `block in ms'
/home/kaspar/.rbenv/versions/2.1.3/lib/ruby/2.1.0/benchmark.rb:294:in `realtime'
activesupport (4.2.0) lib/active_support/core_ext/benchmark.rb:12:in `ms'
actionpack (4.2.0) lib/action_controller/metal/instrumentation.rb:41:in `block in render'
actionpack (4.2.0) lib/action_controller/metal/instrumentation.rb:84:in `cleanup_view_runtime'
activerecord (4.2.0) lib/active_record/railties/controller_runtime.rb:25:in `cleanup_view_runtime'
actionpack (4.2.0) lib/action_controller/metal/instrumentation.rb:40:in `render'
responders (2.0.2) lib/action_controller/responder.rb:258:in `display'
responders (2.0.2) lib/action_controller/responder.rb:212:in `api_behavior'
responders (2.0.2) lib/action_controller/responder.rb:191:in `rescue in to_format'
responders (2.0.2) lib/action_controller/responder.rb:185:in `to_format'
responders (2.0.2) lib/action_controller/responder.rb:163:in `respond'
responders (2.0.2) lib/action_controller/responder.rb:156:in `call'
responders (2.0.2) lib/action_controller/respond_with.rb:203:in `respond_with'
app/controllers/content/media_controller.rb:17:in `show'
actionpack (4.2.0) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
actionpack (4.2.0) lib/abstract_controller/base.rb:198:in `process_action'
actionpack (4.2.0) lib/action_controller/metal/rendering.rb:10:in `process_action'
actionpack (4.2.0) lib/abstract_controller/callbacks.rb:20:in `block in process_action'
activesupport (4.2.0) lib/active_support/callbacks.rb:117:in `call'
activesupport (4.2.0) lib/active_support/callbacks.rb:151:in `block in halting_and_conditional'
activesupport (4.2.0) lib/active_support/callbacks.rb:169:in `block in halting'
activesupport (4.2.0) lib/active_support/callbacks.rb:151:in `block in halting_and_conditional'
activesupport (4.2.0) lib/active_support/callbacks.rb:234:in `block in halting'
activesupport (4.2.0) lib/active_support/callbacks.rb:234:in `block in halting'
activesupport (4.2.0) lib/active_support/callbacks.rb:169:in `block in halting'
activesupport (4.2.0) lib/active_support/callbacks.rb:169:in `block in halting'
activesupport (4.2.0) lib/active_support/callbacks.rb:169:in `block in halting'
activesupport (4.2.0) lib/active_support/callbacks.rb:92:in `_run_callbacks'
activesupport (4.2.0) lib/active_support/callbacks.rb:734:in `_run_process_action_callbacks'
activesupport (4.2.0) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (4.2.0) lib/abstract_controller/callbacks.rb:19:in `process_action'
actionpack (4.2.0) lib/action_controller/metal/rescue.rb:29:in `process_action'
actionpack (4.2.0) lib/action_controller/metal/instrumentation.rb:31:in `block in process_action'
activesupport (4.2.0) lib/active_support/notifications.rb:164:in `block in instrument'
activesupport (4.2.0) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (4.2.0) lib/active_support/notifications.rb:164:in `instrument'
actionpack (4.2.0) lib/action_controller/metal/instrumentation.rb:30:in `process_action'
actionpack (4.2.0) lib/action_controller/metal/params_wrapper.rb:250:in `process_action'
activerecord (4.2.0) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
actionpack (4.2.0) lib/abstract_controller/base.rb:137:in `process'
actionview (4.2.0) lib/action_view/rendering.rb:30:in `process'
actionpack (4.2.0) lib/action_controller/metal.rb:195:in `dispatch'
actionpack (4.2.0) lib/action_controller/metal/rack_delegation.rb:13:in `dispatch'
actionpack (4.2.0) lib/action_controller/metal.rb:236:in `block in action'
actionpack (4.2.0) lib/action_dispatch/routing/route_set.rb:73:in `dispatch'
actionpack (4.2.0) lib/action_dispatch/routing/route_set.rb:42:in `serve'
actionpack (4.2.0) lib/action_dispatch/journey/router.rb:43:in `block in serve'
actionpack (4.2.0) lib/action_dispatch/journey/router.rb:30:in `serve'
actionpack (4.2.0) lib/action_dispatch/routing/route_set.rb:802: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.6.0) lib/rack/etag.rb:24:in `call'
rack (1.6.0) lib/rack/conditionalget.rb:25:in `call'
rack (1.6.0) lib/rack/head.rb:13:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/params_parser.rb:27:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/flash.rb:260:in `call'
rack (1.6.0) lib/rack/session/abstract/id.rb:225:in `context'
rack (1.6.0) lib/rack/session/abstract/id.rb:220:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/cookies.rb:560:in `call'
activerecord (4.2.0) lib/active_record/query_cache.rb:36:in `call'
activerecord (4.2.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:647:in `call'
activerecord (4.2.0) lib/active_record/migration.rb:378:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
activesupport (4.2.0) lib/active_support/callbacks.rb:88:in `_run_callbacks'
activesupport (4.2.0) lib/active_support/callbacks.rb:734:in `_run_call_callbacks'
activesupport (4.2.0) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (4.2.0) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/reloader.rb:73:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/remote_ip.rb:78:in `call'
better_errors (2.1.0) lib/better_errors/middleware.rb:84:in `protected_app_call'
better_errors (2.1.0) lib/better_errors/middleware.rb:79:in `better_errors_call'
better_errors (2.1.0) lib/better_errors/middleware.rb:57:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
railties (4.2.0) lib/rails/rack/logger.rb:38:in `call_app'
railties (4.2.0) lib/rails/rack/logger.rb:20:in `block in call'
activesupport (4.2.0) lib/active_support/tagged_logging.rb:68:in `block in tagged'
activesupport (4.2.0) lib/active_support/tagged_logging.rb:26:in `tagged'
activesupport (4.2.0) lib/active_support/tagged_logging.rb:68:in `tagged'
railties (4.2.0) lib/rails/rack/logger.rb:20:in `call'
quiet_assets (1.1.0) lib/quiet_assets.rb:27:in `call_with_quiet_assets'
actionpack (4.2.0) lib/action_dispatch/middleware/request_id.rb:21:in `call'
rack (1.6.0) lib/rack/methodoverride.rb:22:in `call'
rack (1.6.0) lib/rack/runtime.rb:18:in `call'
activesupport (4.2.0) lib/active_support/cache/strategy/local_cache_middleware.rb:28:in `call'
rack (1.6.0) lib/rack/lock.rb:17:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/static.rb:113:in `call'
rack (1.6.0) lib/rack/sendfile.rb:113:in `call'
railties (4.2.0) lib/rails/engine.rb:518:in `call'
railties (4.2.0) lib/rails/application.rb:164:in `call'
passenger (4.0.56) lib/phusion_passenger/rack/thread_handler_extension.rb:74:in `process_request'
passenger (4.0.56) lib/phusion_passenger/request_handler/thread_handler.rb:141:in `accept_and_process_next_request'
passenger (4.0.56) lib/phusion_passenger/request_handler/thread_handler.rb:109:in `main_loop'
passenger (4.0.56) lib/phusion_passenger/request_handler.rb:455:in `block (3 levels) in start_threads'
Worth noting maybe that if I remove both of the :user includes from the new include: method, then everything works. But I want each comment to also include the user that created it and medium to also include the user that uploaded it.
What could be the problem here? Let me know if some more info is needed.
EDIT: The problem seems to be only with the :user for comments:.
Posting my comments serializer here:
class CommentSerializer < ActiveModel::Serializer
attributes :id,
:text,
:user_id,
:medium_id
has_one :user
end
I encountered the same error using the built in ActiveModel serializer for JSON. You can overwrite a model's as_json method with similar syntax to your respond_with call. Using your models I had
include: [{comments: :user} ... ]
when what I needed was
include: [{comments: {include: [:user]}}, ... ]
See if the following change fixes your problem (if you're still having it).
Change
respond_with medium, include: [{comments: :user}, :likes, :user]
to
respond_with medium, include: [{comments: {include: [:user]}}, :likes, :user]

Does Kaminari Work with Inherited Resources?

Does anyone know whether the Kaminari gem works with Inherited Resources, because I'm trying to keep my code dry and don't want to repeat myself?
What the plan is, is to render 3 different tables i.e. an Errors table, Messages table and Subscribers table using one partial. However because I'm using Inherited Resources I need all of the code that I'd use in the errors controller, messages controller and subscribers controller, to come through the Admin Application Controller.
I hope this makes sense to anyone reading this
Here's my code:
Admin Application Controller
class Admin::ApplicationController < InheritedResources::Base
protect_from_forgery
include ResourcesHelper
layout "admin"
#Setup
before_filter :set_resource_variable
before_filter :set_pagination_variable, only: :index
#Authentication
skip_before_filter :authenticate_user!
before_filter :authenticate_admin!
#Authorization
skip_before_filter :check_authentication
#Index
#Custom Index For Application/Index (no inheritance)
def index
#users = User.all
#attributes = %w(messages subscribers)
end
#Create
def create
create! { collection_path }
end
#Update
def update
update! { collection_path }
end
private
#Set Model Variable
def set_resource_variable
#resource = self.resource_class
#model = "#{#resource}".downcase.to_sym
end
#Strong Params
def permitted_params
attributes = attributes(#resource) + %w(user_id admin_id) + [image_pages_attributes: [:caption, image_attributes: [:image]]]
params.permit(#model => attributes)
end
end
Errors Controller
def collection
#errors ||= end_of_association_chain.page params[:page]
end
Table Partial
<h2><%= model %></h2>
<% unless collection.blank? %>
<table class="sort">
<thead>
<tr>
<% model.attribute_names.each do |attr| %>
<th><%= model.human_attribute_name(attr) %></th>
<% end %>
<th colspan="2"> </th>
<% if model.name == "Error" %><th> </th><% end %>
</tr>
</thead>
<tbody>
<%= render partial: "admin/resources/table/row", collection: collection, as: :resource, locals: {model: model} %>
</tbody>
</table>
Here is the stack trace.
This error was thrown due to a current_page error:
undefined method `current_page' for nil:NilClass
Stack Trace
kaminari (0.15.0) lib/kaminari/helpers/action_view_extension.rb:18:in `paginate'
app/views/admin/resources/_table.html.erb:18:in `_app_views_admin_resources__table_html_erb___69500511_4075212'
actionpack (4.0.2) lib/action_view/template.rb:143:in `block in render'
activesupport (4.0.2) lib/active_support/notifications.rb:161:in `instrument'
actionpack (4.0.2) lib/action_view/template.rb:141:in `render'
actionpack (4.0.2) lib/action_view/renderer/partial_renderer.rb:306:in `render_partial'
actionpack (4.0.2) lib/action_view/renderer/partial_renderer.rb:279:in `block in render'
actionpack (4.0.2) lib/action_view/renderer/abstract_renderer.rb:38:in `block in instrument'
activesupport (4.0.2) lib/active_support/notifications.rb:159:in `block in instrument'
activesupport (4.0.2) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (4.0.2) lib/active_support/notifications.rb:159:in `instrument'
actionpack (4.0.2) lib/action_view/renderer/abstract_renderer.rb:38:in `instrument'
actionpack (4.0.2) lib/action_view/renderer/partial_renderer.rb:278:in `render'
actionpack (4.0.2) lib/action_view/renderer/renderer.rb:47:in `render_partial'
actionpack (4.0.2) lib/action_view/renderer/renderer.rb:21:in `render'
actionpack (4.0.2) lib/action_view/helpers/rendering_helper.rb:24:in `render'
app/views/admin/application/index.html.erb:14:in `block in _app_views_admin_application_index_html_erb__1045387382_50813388'
app/views/admin/application/index.html.erb:12:in `each'
app/views/admin/application/index.html.erb:12:in `_app_views_admin_application_index_html_erb__1045387382_50813388'
actionpack (4.0.2) lib/action_view/template.rb:143:in `block in render'
activesupport (4.0.2) lib/active_support/notifications.rb:161:in `instrument'
actionpack (4.0.2) lib/action_view/template.rb:141:in `render'
actionpack (4.0.2) lib/action_view/renderer/template_renderer.rb:49:in `block (2 levels) in render_template'
actionpack (4.0.2) lib/action_view/renderer/abstract_renderer.rb:38:in `block in instrument'
activesupport (4.0.2) lib/active_support/notifications.rb:159:in `block in instrument'
activesupport (4.0.2) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (4.0.2) lib/active_support/notifications.rb:159:in `instrument'
actionpack (4.0.2) lib/action_view/renderer/abstract_renderer.rb:38:in `instrument'
actionpack (4.0.2) lib/action_view/renderer/template_renderer.rb:48:in `block in render_template'
actionpack (4.0.2) lib/action_view/renderer/template_renderer.rb:56:in `render_with_layout'
actionpack (4.0.2) lib/action_view/renderer/template_renderer.rb:47:in `render_template'
actionpack (4.0.2) lib/action_view/renderer/template_renderer.rb:17:in `render'
actionpack (4.0.2) lib/action_view/renderer/renderer.rb:42:in `render_template'
actionpack (4.0.2) lib/action_view/renderer/renderer.rb:23:in `render'
actionpack (4.0.2) lib/abstract_controller/rendering.rb:127:in `_render_template'
actionpack (4.0.2) lib/action_controller/metal/streaming.rb:219:in `_render_template'
actionpack (4.0.2) lib/abstract_controller/rendering.rb:120:in `render_to_body'
actionpack (4.0.2) lib/action_controller/metal/rendering.rb:33:in `render_to_body'
actionpack (4.0.2) lib/action_controller/metal/renderers.rb:26:in `render_to_body'
actionpack (4.0.2) lib/abstract_controller/rendering.rb:97:in `render'
actionpack (4.0.2) lib/action_controller/metal/rendering.rb:16:in `render'
actionpack (4.0.2) lib/action_controller/metal/instrumentation.rb:41:in `block (2 levels) in render'
activesupport (4.0.2) lib/active_support/core_ext/benchmark.rb:12:in `block in ms'
C:/RailsInstaller/Ruby2.0.0/lib/ruby/2.0.0/benchmark.rb:296:in `realtime'
activesupport (4.0.2) lib/active_support/core_ext/benchmark.rb:12:in `ms'
actionpack (4.0.2) lib/action_controller/metal/instrumentation.rb:41:in `block in render'
actionpack (4.0.2) lib/action_controller/metal/instrumentation.rb:84:in `cleanup_view_runtime'
activerecord (4.0.2) lib/active_record/railties/controller_runtime.rb:25:in `cleanup_view_runtime'
actionpack (4.0.2) lib/action_controller/metal/instrumentation.rb:40:in `render'
actionpack (4.0.2) lib/action_controller/metal/implicit_render.rb:10:in `default_render'
actionpack (4.0.2) lib/action_controller/metal/implicit_render.rb:5:in `send_action'
actionpack (4.0.2) lib/abstract_controller/base.rb:189:in `process_action'
actionpack (4.0.2) lib/action_controller/metal/rendering.rb:10:in `process_action'
actionpack (4.0.2) lib/abstract_controller/callbacks.rb:18:in `block in process_action'
activesupport (4.0.2) lib/active_support/callbacks.rb:433:in `_run__894777034__process_action__callbacks'
activesupport (4.0.2) lib/active_support/callbacks.rb:80:in `run_callbacks'
actionpack (4.0.2) lib/abstract_controller/callbacks.rb:17:in `process_action'
actionpack (4.0.2) lib/action_controller/metal/rescue.rb:29:in `process_action'
actionpack (4.0.2) lib/action_controller/metal/instrumentation.rb:31:in `block in process_action'
activesupport (4.0.2) lib/active_support/notifications.rb:159:in `block in instrument'
activesupport (4.0.2) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (4.0.2) lib/active_support/notifications.rb:159:in `instrument'
actionpack (4.0.2) lib/action_controller/metal/instrumentation.rb:30:in `process_action'
actionpack (4.0.2) lib/action_controller/metal/params_wrapper.rb:245:in `process_action'
activerecord (4.0.2) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
actionpack (4.0.2) lib/abstract_controller/base.rb:136:in `process'
actionpack (4.0.2) lib/abstract_controller/rendering.rb:44:in `process'
actionpack (4.0.2) lib/action_controller/metal.rb:195:in `dispatch'
actionpack (4.0.2) lib/action_controller/metal/rack_delegation.rb:13:in `dispatch'
actionpack (4.0.2) lib/action_controller/metal.rb:231:in `block in action'
actionpack (4.0.2) lib/action_dispatch/routing/route_set.rb:80:in `call'
actionpack (4.0.2) lib/action_dispatch/routing/route_set.rb:80:in `dispatch'
actionpack (4.0.2) lib/action_dispatch/routing/route_set.rb:48:in `call'
actionpack (4.0.2) lib/action_dispatch/journey/router.rb:71:in `block in call'
actionpack (4.0.2) lib/action_dispatch/journey/router.rb:59:in `each'
actionpack (4.0.2) lib/action_dispatch/journey/router.rb:59:in `call'
actionpack (4.0.2) lib/action_dispatch/routing/route_set.rb:680:in `call'
lib/error_alert.rb:14:in `call'
rack-cors (0.2.9) lib/rack/cors.rb:54: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 `catch'
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:25:in `call'
rack (1.5.2) lib/rack/head.rb:11:in `call'
actionpack (4.0.2) lib/action_dispatch/middleware/params_parser.rb:27:in `call'
actionpack (4.0.2) 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.2) lib/action_dispatch/middleware/cookies.rb:486:in `call'
activerecord (4.0.2) lib/active_record/query_cache.rb:36:in `call'
activerecord (4.0.2) lib/active_record/connection_adapters/abstract/connection_pool.rb:626:in `call'
activerecord (4.0.2) lib/active_record/migration.rb:369:in `call'
actionpack (4.0.2) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
activesupport (4.0.2) lib/active_support/callbacks.rb:373:in `_run__692376707__call__callbacks'
activesupport (4.0.2) lib/active_support/callbacks.rb:80:in `run_callbacks'
actionpack (4.0.2) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (4.0.2) lib/action_dispatch/middleware/reloader.rb:64:in `call'
actionpack (4.0.2) lib/action_dispatch/middleware/remote_ip.rb:76:in `call'
actionpack (4.0.2) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
actionpack (4.0.2) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
railties (4.0.2) lib/rails/rack/logger.rb:38:in `call_app'
railties (4.0.2) lib/rails/rack/logger.rb:20:in `block in call'
activesupport (4.0.2) lib/active_support/tagged_logging.rb:67:in `block in tagged'
activesupport (4.0.2) lib/active_support/tagged_logging.rb:25:in `tagged'
activesupport (4.0.2) lib/active_support/tagged_logging.rb:67:in `tagged'
railties (4.0.2) lib/rails/rack/logger.rb:20:in `call'
actionpack (4.0.2) 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.2) 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.2) lib/action_dispatch/middleware/static.rb:64:in `call'
rack (1.5.2) lib/rack/sendfile.rb:112:in `call'
railties (4.0.2) lib/rails/engine.rb:511:in `call'
railties (4.0.2) 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 `catch'
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-x86 (mingw32) lib/eventmachine.rb:187:in `run_machine'
eventmachine-1.0.3-x86 (mingw32) 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.2) lib/rails/commands/server.rb:84:in `start'
railties (4.0.2) lib/rails/commands.rb:76:in `block in <top (required)>'
railties (4.0.2) lib/rails/commands.rb:71:in `tap'
railties (4.0.2) lib/rails/commands.rb:71:in `<top (required)>'
bin/rails:4:in `require'
bin/rails:4:in `<main>'
I think it does judging from this snippet from https://github.com/josevalim/inherited_resources
class ProjectsController < InheritedResources::Base
protected
def collection
#projects ||= end_of_association_chain.paginate(:page => params[:page])
end
end
So for Kaminari you might do this:
class ProjectsController < InheritedResources::Base
protected
def collection
#projects ||= end_of_association_chain.page params[:page]
end
end
Although I haven't had a chance to try it yet.
I have tested this and it works perfectly.

LoadError in Users::OmniauthCallbacksController#facebook - Rails 4

well, I am trying to code a system that uses facebook login. When I click on the facebook link it goes to facebook page for authentication and on the callback show me this error: Unable to autoload constant Users::OmniauthCallbacksController, expected path/app/controllers/users/omniauth_callbacks_controller.rb to define it.
I am using devise gem, omniauth gem, ruby 2 and rails 4.
My user_controller.rb
class User::OmniauthCallbacksController < Devise::OmniauthCallbacksController
def facebook
#user = User.find_for_facebook_oauth(request.env['omniauth.auth'], current_user)
if #user.persisted?
sign_in_and_redirect #user, :event => :authentication #this will throw if #user is not activated
set_flash_message(:notice, :success, :kind => 'Facebook') if is_navigational_format?
else
session['devise.facebook_data'] = request.env['omniauth.auth']
redirect_to new_user_registration_url
end
end
end
My user.rb
class User < ActiveRecord::Base
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable, :omniauthable
def self.find_for_facebook_oauth(auth, signed_in_resource = nil)
user = User.where(:provider => auth.provider, :uid => auth.uid).first
if user
return user
else
registered_user = User.where(:email => auth.info.email).first
if registered_user
return registered_user
else
user = User.create(name:auth.extra.raw_info.name,
provider:auth.provider,
uid:auth.uid,
email:auth.info.email,
password:Devise.friendly_token[0,20],
)
end
end
end
end
On routes.rb I have this line:
devise_for :users, :controllers => { :omniauth_callbacks => 'users/omniauth_callbacks' }
The Full Trace is this:
activesupport (4.0.0) lib/active_support/dependencies.rb:463:in `load_missing_constant'
activesupport (4.0.0) lib/active_support/dependencies.rb:183:in `const_missing'
activesupport (4.0.0) lib/active_support/inflector/methods.rb:228:in `const_get'
activesupport (4.0.0) lib/active_support/inflector/methods.rb:228:in `block in constantize'
activesupport (4.0.0) lib/active_support/inflector/methods.rb:224:in `each'
activesupport (4.0.0) lib/active_support/inflector/methods.rb:224:in `inject'
activesupport (4.0.0) lib/active_support/inflector/methods.rb:224:in `constantize'
activesupport (4.0.0) lib/active_support/dependencies.rb:534:in `get'
activesupport (4.0.0) lib/active_support/dependencies.rb:565:in `constantize'
actionpack (4.0.0) lib/action_dispatch/routing/route_set.rb:76:in `controller_reference'
actionpack (4.0.0) lib/action_dispatch/routing/route_set.rb:66:in `controller'
actionpack (4.0.0) lib/action_dispatch/routing/route_set.rb:44:in `call'
actionpack (4.0.0) lib/action_dispatch/routing/mapper.rb:44: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 `each'
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'
omniauth (1.1.4) lib/omniauth/strategy.rb:184:in `call!'
omniauth (1.1.4) lib/omniauth/strategy.rb:164:in `call'
omniauth (1.1.4) lib/omniauth/strategy.rb:184:in `call!'
omniauth (1.1.4) lib/omniauth/strategy.rb:164:in `call'
omniauth (1.1.4) lib/omniauth/strategy.rb:401:in `call_app!'
omniauth (1.1.4) lib/omniauth/strategy.rb:363:in `callback_phase'
omniauth-oauth2 (1.1.1) lib/omniauth/strategies/oauth2.rb:77:in `callback_phase'
omniauth (1.1.4) lib/omniauth/strategy.rb:226:in `callback_call'
omniauth (1.1.4) lib/omniauth/strategy.rb:182:in `call!'
omniauth (1.1.4) lib/omniauth/strategy.rb:164: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 `catch'
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:25:in `call'
rack (1.5.2) lib/rack/head.rb:11: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'
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__878755641__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:/Development/Ruby200/lib/ruby/2.0.0/webrick/httpserver.rb:138:in `service'
C:/Development/Ruby200/lib/ruby/2.0.0/webrick/httpserver.rb:94:in `run'
C:/Development/Ruby200/lib/ruby/2.0.0/webrick/server.rb:295:in `block in start_thread'
So that's my problem I hope someone can help me.
EDIT: rather than what I implied to, my callbacks controller is called omniauth_callbacks_controller.rb.
1. As sevenseacat suggested I changed the reference from users to user on my route file, but the problem still happened.
2. As *uno_ordinary* suggested I added :omniauth_providers => :facebook on my model but after that I received a new error when starting the server:
=> Booting WEBrick
=> Rails 4.0.0 application starting in development on http://0.0.0.0:3000
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
Exiting
C:3:in `rescue in execute_if_updated': Rails::Application::RoutesReloader#execute_if_updated delegated to updater.execute_if_updated, but updater is nil: #<Rails::Application::RoutesReloader:0x4375db8 #paths=["C:/Users/Diogo de Lima/Documents/Development/Ruby on Rails/Rhodnius/config/routes.rb"], #route_sets=[#<ActionDispatch::Routing::RouteSet:0x449da98>]> (RuntimeError)
from C:131071:in `execute_if_updated'
from C:/Development/Ruby200/lib/ruby/gems/2.0.0/gems/railties-4.0.0/lib/rails/application/finisher.rb:69:in `block in <module:Finisher>'
from C:/Development/Ruby200/lib/ruby/gems/2.0.0/gems/railties-4.0.0/lib/rails/initializable.rb:30:in `instance_exec'
from C:/Development/Ruby200/lib/ruby/gems/2.0.0/gems/railties-4.0.0/lib/rails/initializable.rb:30:in `run'
from C:/Development/Ruby200/lib/ruby/gems/2.0.0/gems/railties-4.0.0/lib/rails/initializable.rb:55:in `block in run_initializers'
from C:/Development/Ruby200/lib/ruby/2.0.0/tsort.rb:150:in `block in tsort_each'
from C:/Development/Ruby200/lib/ruby/2.0.0/tsort.rb:183:in `block (2 levels) in each_strongly_connected_component'
from C:/Development/Ruby200/lib/ruby/2.0.0/tsort.rb:219:in `each_strongly_connected_component_from'
from C:/Development/Ruby200/lib/ruby/2.0.0/tsort.rb:182:in `block in each_strongly_connected_component'
from C:/Development/Ruby200/lib/ruby/2.0.0/tsort.rb:180:in `each'
from C:/Development/Ruby200/lib/ruby/2.0.0/tsort.rb:180:in `each_strongly_connected_component'
from C:/Development/Ruby200/lib/ruby/2.0.0/tsort.rb:148:in `tsort_each'
from C:/Development/Ruby200/lib/ruby/gems/2.0.0/gems/railties-4.0.0/lib/rails/initializable.rb:54:in `run_initializers'
from C:/Development/Ruby200/lib/ruby/gems/2.0.0/gems/railties-4.0.0/lib/rails/application.rb:215:in `initialize!'
from C:/Development/Ruby200/lib/ruby/gems/2.0.0/gems/railties-4.0.0/lib/rails/railtie/configurable.rb:30:in `method_missing'
from C:/Users/Diogo de Lima/Documents/Development/Ruby on Rails/Rhodnius/config/environment.rb:5:in `<top (required)>'
from C:/Development/Ruby200/lib/ruby/gems/2.0.0/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:228:in `require'
from C:/Development/Ruby200/lib/ruby/gems/2.0.0/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:228:in `block in require'
from C:/Development/Ruby200/lib/ruby/gems/2.0.0/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:213:in `load_dependency'
from C:/Development/Ruby200/lib/ruby/gems/2.0.0/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:228:in `require'
from C:/Users/Diogo de Lima/Documents/Development/Ruby on Rails/Rhodnius/config.ru:3:in `block in <main>'
from C:/Development/Ruby200/lib/ruby/gems/2.0.0/gems/rack-1.5.2/lib/rack/builder.rb:55:in `instance_eval'
from C:/Development/Ruby200/lib/ruby/gems/2.0.0/gems/rack-1.5.2/lib/rack/builder.rb:55:in `initialize'
from C:/Users/Diogo de Lima/Documents/Development/Ruby on Rails/Rhodnius/config.ru:in `new'
from C:/Users/Diogo de Lima/Documents/Development/Ruby on Rails/Rhodnius/config.ru:in `<main>'
from C:/Development/Ruby200/lib/ruby/gems/2.0.0/gems/rack-1.5.2/lib/rack/builder.rb:49:in `eval'
from C:/Development/Ruby200/lib/ruby/gems/2.0.0/gems/rack-1.5.2/lib/rack/builder.rb:49:in `new_from_string'
from C:/Development/Ruby200/lib/ruby/gems/2.0.0/gems/rack-1.5.2/lib/rack/builder.rb:40:in `parse_file'
from C:/Development/Ruby200/lib/ruby/gems/2.0.0/gems/rack-1.5.2/lib/rack/server.rb:277:in `build_app_and_options_from_config'
from C:/Development/Ruby200/lib/ruby/gems/2.0.0/gems/rack-1.5.2/lib/rack/server.rb:199:in `app'
from C:/Development/Ruby200/lib/ruby/gems/2.0.0/gems/railties-4.0.0/lib/rails/commands/server.rb:48:in `app'
from C:/Development/Ruby200/lib/ruby/gems/2.0.0/gems/rack-1.5.2/lib/rack/server.rb:314:in `wrapped_app'
from C:/Development/Ruby200/lib/ruby/gems/2.0.0/gems/railties-4.0.0/lib/rails/commands/server.rb:75:in `start'
from C:/Development/Ruby200/lib/ruby/gems/2.0.0/gems/railties-4.0.0/lib/rails/commands.rb:78:in `block in <top (required)>'
from C:/Development/Ruby200/lib/ruby/gems/2.0.0/gems/railties-4.0.0/lib/rails/commands.rb:73:in `tap'
from C:/Development/Ruby200/lib/ruby/gems/2.0.0/gems/railties-4.0.0/lib/rails/commands.rb:73:in `<top (required)>'
from bin/rails:4:in `require'
from bin/rails:4:in `<main>'
If your callbacks controller is in a file called user_controller.rb (as your post implies), this is incorrect.
To follow Rails' naming conventions, it needs to be in app/controllers/users/omniauth_callbacks_controller.rb (as the error tells you).
You also have a problem with namespacing - your route for the callbacks controller refers to users (plural), while your controller namespace is User (singular).
Try to add to User model the following:
:omniauthable, :omniauth_providers => [:facebook]

active admin called nil id

im working with active admin i have collection_select or dropdown box that populates the packages and crews im just wondering i why this
undefined method `[]' for nil:NilClass`
i dont know what happened but it run few days ago and tested it once but now it raises this error are there possible way to solve this?
def create
#package = Package.find(params[:package_crew][:package_id])
crew = Crew.find(params[:package_crew][:crew_id] )
#package_crew = #package.add_crew(crew.id)
if #package_crew.save
redirect_to {admin_package_crew_url}
end
end
thanks in advance more power to us all
i tried this
def create
#pid = params[:package_crew][:crew_id] if params[:package_crew]
pid,cid = 2 #tried nil,0..10
if params[:package_crew]
pid = params[:package_crew][:package_id]
cid = params[:package_crew][:crew_id]
end
#package = Package.find_by_id(pid)
crew = Crew.find_by_id(cid)
##package = Package.find(params[:package_crew][:package_id])
#crew = Crew.find(params[:package_crew][:crew_id] )
#package_crew = #package.add_crew(crew.id)
if #package_crew.save
redirect_to {admin_package_crew_url}
end
end
add_crew method
def add_crew(crew_id)
current_package = package_crews.find_by_crew_id(crew_id)
if current_package
current_package.quantity = current_package.quantity.to_i + 1
else
current_package = package_crews.build(:crew_id => crew_id)
current_package.price = current_package.crew.price
end
current_package
end
moving parameters
{"utf8"=>"✓",
"authenticity_token"=>"n4WZpQpES6mnSO12oGKV/MeoxAVvV9OmJQKfhcpnvQM=",
"crew_for_package"=>{"package_id"=>"1",
"crew_id"=>"1",
"quantity"=>"1"},
"commit"=>"Create Package crew"}
stack error
app/admin/package_crews.rb:35:in `create'
actionpack (3.2.1) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
actionpack (3.2.1) lib/abstract_controller/base.rb:167:in `process_action'
actionpack (3.2.1) lib/action_controller/metal/rendering.rb:10:in `process_action'
actionpack (3.2.1) lib/abstract_controller/callbacks.rb:18:in `block in process_action'
activesupport (3.2.1) lib/active_support/callbacks.rb:447:in `_run__304549499__process_action__775442107__callbacks'
activesupport (3.2.1) lib/active_support/callbacks.rb:405:in `__run_callback'
activesupport (3.2.1) lib/active_support/callbacks.rb:385:in `_run_process_action_callbacks'
activesupport (3.2.1) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (3.2.1) lib/abstract_controller/callbacks.rb:17:in `process_action'
actionpack (3.2.1) lib/action_controller/metal/rescue.rb:29:in `process_action'
actionpack (3.2.1) lib/action_controller/metal/instrumentation.rb:30:in `block in process_action'
activesupport (3.2.1) lib/active_support/notifications.rb:123:in `block in instrument'
activesupport (3.2.1) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (3.2.1) lib/active_support/notifications.rb:123:in `instrument'
actionpack (3.2.1) lib/action_controller/metal/instrumentation.rb:29:in `process_action'
actionpack (3.2.1) lib/action_controller/metal/params_wrapper.rb:205:in `process_action'
activerecord (3.2.1) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
actionpack (3.2.1) lib/abstract_controller/base.rb:121:in `process'
actionpack (3.2.1) lib/abstract_controller/rendering.rb:45:in `process'
actionpack (3.2.1) lib/action_controller/metal.rb:203:in `dispatch'
actionpack (3.2.1) lib/action_controller/metal/rack_delegation.rb:14:in `dispatch'
actionpack (3.2.1) lib/action_controller/metal.rb:246:in `block in action'
actionpack (3.2.1) lib/action_dispatch/routing/route_set.rb:66:in `call'
actionpack (3.2.1) lib/action_dispatch/routing/route_set.rb:66:in `dispatch'
actionpack (3.2.1) lib/action_dispatch/routing/route_set.rb:30:in `call'
journey (1.0.3) lib/journey/router.rb:68:in `block 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.1) lib/action_dispatch/routing/route_set.rb:589:in `call'
sass (3.1.15) lib/sass/plugin/rack.rb:54:in `call'
warden (1.1.1) lib/warden/manager.rb:35:in `block in call'
warden (1.1.1) lib/warden/manager.rb:34:in `catch'
warden (1.1.1) lib/warden/manager.rb:34:in `call'
actionpack (3.2.1) 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:35:in `call'
actionpack (3.2.1) lib/action_dispatch/middleware/head.rb:14:in `call'
actionpack (3.2.1) lib/action_dispatch/middleware/params_parser.rb:21:in `call'
actionpack (3.2.1) 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.1) lib/action_dispatch/middleware/cookies.rb:338:in `call'
activerecord (3.2.1) lib/active_record/query_cache.rb:64:in `call'
activerecord (3.2.1) lib/active_record/connection_adapters/abstract/connection_pool.rb:443:in `call'
actionpack (3.2.1) lib/action_dispatch/middleware/callbacks.rb:28:in `block in call'
activesupport (3.2.1) lib/active_support/callbacks.rb:405:in `_run__1039351831__call__833288071__callbacks'
activesupport (3.2.1) lib/active_support/callbacks.rb:405:in `__run_callback'
activesupport (3.2.1) lib/active_support/callbacks.rb:385:in `_run_call_callbacks'
activesupport (3.2.1) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (3.2.1) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (3.2.1) lib/action_dispatch/middleware/reloader.rb:65:in `call'
actionpack (3.2.1) lib/action_dispatch/middleware/remote_ip.rb:31:in `call'
actionpack (3.2.1) lib/action_dispatch/middleware/debug_exceptions.rb:16:in `call'
actionpack (3.2.1) lib/action_dispatch/middleware/show_exceptions.rb:56:in `call'
railties (3.2.1) lib/rails/rack/logger.rb:26:in `call_app'
railties (3.2.1) lib/rails/rack/logger.rb:16:in `call'
actionpack (3.2.1) 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.1) 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.1) lib/action_dispatch/middleware/static.rb:53:in `call'
railties (3.2.1) lib/rails/engine.rb:479:in `call'
railties (3.2.1) lib/rails/application.rb:220:in `call'
railties (3.2.1) lib/rails/railtie/configurable.rb:30:in `method_missing'
/home/led/.passenger/standalone/3.0.11-x86-ruby1.9.3-linux-gcc4.6.3-1002/support/lib/phusion_passenger/rack/request_handler.rb:96:in `process_request'
/home/led/.passenger/standalone/3.0.11-x86-ruby1.9.3-linux-gcc4.6.3-1002/support/lib/phusion_passenger/abstract_request_handler.rb:513:in `accept_and_process_next_request'
/home/led/.passenger/standalone/3.0.11-x86-ruby1.9.3-linux-gcc4.6.3-1002/support/lib/phusion_passenger/abstract_request_handler.rb:274:in `main_loop'
/home/led/.passenger/standalone/3.0.11-x86-ruby1.9.3-linux-gcc4.6.3-1002/support/lib/phusion_passenger/rack/application_spawner.rb:206:in `start_request_handler'
/home/led/.passenger/standalone/3.0.11-x86-ruby1.9.3-linux-gcc4.6.3-1002/support/lib/phusion_passenger/rack/application_spawner.rb:171:in `block in handle_spawn_application'
/home/led/.passenger/standalone/3.0.11-x86-ruby1.9.3-linux-gcc4.6.3-1002/support/lib/phusion_passenger/utils.rb:479:in `safe_fork'
/home/led/.passenger/standalone/3.0.11-x86-ruby1.9.3-linux-gcc4.6.3-1002/support/lib/phusion_passenger/rack/application_spawner.rb:166:in `handle_spawn_application'
/home/led/.passenger/standalone/3.0.11-x86-ruby1.9.3-linux-gcc4.6.3-1002/support/lib/phusion_passenger/abstract_server.rb:357:in `server_main_loop'
/home/led/.passenger/standalone/3.0.11-x86-ruby1.9.3-linux-gcc4.6.3-1002/support/lib/phusion_passenger/abstract_server.rb:206:in `start_synchronously'
/home/led/.passenger/standalone/3.0.11-x86-ruby1.9.3-linux-gcc4.6.3-1002/support/lib/phusion_passenger/abstract_server.rb:180:in `start'
/home/led/.passenger/standalone/3.0.11-x86-ruby1.9.3-linux-gcc4.6.3-1002/support/lib/phusion_passenger/rack/application_spawner.rb:129:in `start'
/home/led/.passenger/standalone/3.0.11-x86-ruby1.9.3-linux-gcc4.6.3-1002/support/lib/phusion_passenger/spawn_manager.rb:253:in `block (2 levels) in spawn_rack_application'
/home/led/.passenger/standalone/3.0.11-x86-ruby1.9.3-linux-gcc4.6.3-1002/support/lib/phusion_passenger/abstract_server_collection.rb:132:in `lookup_or_add'
/home/led/.passenger/standalone/3.0.11-x86-ruby1.9.3-linux-gcc4.6.3-1002/support/lib/phusion_passenger/spawn_manager.rb:246:in `block in spawn_rack_application'
/home/led/.passenger/standalone/3.0.11-x86-ruby1.9.3-linux-gcc4.6.3-1002/support/lib/phusion_passenger/abstract_server_collection.rb:82:in `block in synchronize'
<internal:prelude>:10:in `synchronize'
/home/led/.passenger/standalone/3.0.11-x86-ruby1.9.3-linux-gcc4.6.3-1002/support/lib/phusion_passenger/abstract_server_collection.rb:79:in `synchronize'
/home/led/.passenger/standalone/3.0.11-x86-ruby1.9.3-linux-gcc4.6.3-1002/support/lib/phusion_passenger/spawn_manager.rb:244:in `spawn_rack_application'
/home/led/.passenger/standalone/3.0.11-x86-ruby1.9.3-linux-gcc4.6.3-1002/support/lib/phusion_passenger/spawn_manager.rb:137:in `spawn_application'
/home/led/.passenger/standalone/3.0.11-x86-ruby1.9.3-linux-gcc4.6.3-1002/support/lib/phusion_passenger/spawn_manager.rb:275:in `handle_spawn_application'
/home/led/.passenger/standalone/3.0.11-x86-ruby1.9.3-linux-gcc4.6.3-1002/support/lib/phusion_passenger/abstract_server.rb:357:in `server_main_loop'
/home/led/.passenger/standalone/3.0.11-x86-ruby1.9.3-linux-gcc4.6.3-1002/support/lib/phusion_passenger/abstract_server.rb:206:in `start_synchronously'
/home/led/.passenger/standalone/3.0.11-x86-ruby1.9.3-linux-gcc4.6.3-1002/support/helper-scripts/passenger-spawn-server:99:in `<main>'
As i can understand,
your params[:package_crew] is returning nil
check your params[:package_crew]
try following
pid,cid = 0
if params[:package_crew]
pid = params[:package_crew][:package_id]
cid = params[:package_crew][:crew_id]
end
#package = Package.find(pid)
#crew = Crew.find(cid)
i would suggest rather use this.
Package.find_by_id(pid) # this wont raise exception, when record is not found
Crew.find_by_id(cid)

Called id for nil, Active admin

im working with active admin i have collection_select or dropdown box that populates the packages and crews im just wondering i why this
undefined method `[]' for nil:NilClass`
i dont know what happened but it run few days ago and tested it once but now it raises this error are there possible way to solve this?
def create
#package = Package.find(params[:package_crew][:package_id])
crew = Crew.find(params[:package_crew][:crew_id] )
#package_crew = #package.add_crew(crew.id)
if #package_crew.save
redirect_to {admin_package_crew_url}
end
end
thanks in advance more power to us all
i tried this and
Called id for nil, which would mistakenly be 4 -- if you really wanted the id of nil, use object_id
tried create
def create
#pid = params[:package_crew][:crew_id] if params[:package_crew]
pid,cid = 2 #tried nil,0..10
if params[:package_crew]
pid = params[:package_crew][:package_id]
cid = params[:package_crew][:crew_id]
end
#package = Package.find_by_id(pid)
crew = Crew.find_by_id(cid)
##package = Package.find(params[:package_crew][:package_id])
#crew = Crew.find(params[:package_crew][:crew_id] )
#package_crew = #package.add_crew(crew.id)
if #package_crew.save
redirect_to {admin_package_crew_url}
end
end
add_crew method
def add_crew(crew_id)
current_package = package_crews.find_by_crew_id(crew_id)
if current_package
current_package.quantity = current_package.quantity.to_i + 1
else
current_package = package_crews.build(:crew_id => crew_id)
current_package.price = current_package.crew.price
end
current_package
end
moving parameters
{"utf8"=>"✓",
"authenticity_token"=>"n4WZpQpES6mnSO12oGKV/MeoxAVvV9OmJQKfhcpnvQM=",
"crew_for_package"=>{"package_id"=>"1",
"crew_id"=>"1",
"quantity"=>"1"},
"commit"=>"Create Package crew"}
stack error
app/admin/package_crews.rb:35:in `create'
actionpack (3.2.1) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
actionpack (3.2.1) lib/abstract_controller/base.rb:167:in `process_action'
actionpack (3.2.1) lib/action_controller/metal/rendering.rb:10:in `process_action'
actionpack (3.2.1) lib/abstract_controller/callbacks.rb:18:in `block in process_action'
activesupport (3.2.1) lib/active_support/callbacks.rb:447:in `_run__304549499__process_action__775442107__callbacks'
activesupport (3.2.1) lib/active_support/callbacks.rb:405:in `__run_callback'
activesupport (3.2.1) lib/active_support/callbacks.rb:385:in `_run_process_action_callbacks'
activesupport (3.2.1) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (3.2.1) lib/abstract_controller/callbacks.rb:17:in `process_action'
actionpack (3.2.1) lib/action_controller/metal/rescue.rb:29:in `process_action'
actionpack (3.2.1) lib/action_controller/metal/instrumentation.rb:30:in `block in process_action'
activesupport (3.2.1) lib/active_support/notifications.rb:123:in `block in instrument'
activesupport (3.2.1) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (3.2.1) lib/active_support/notifications.rb:123:in `instrument'
actionpack (3.2.1) lib/action_controller/metal/instrumentation.rb:29:in `process_action'
actionpack (3.2.1) lib/action_controller/metal/params_wrapper.rb:205:in `process_action'
activerecord (3.2.1) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
actionpack (3.2.1) lib/abstract_controller/base.rb:121:in `process'
actionpack (3.2.1) lib/abstract_controller/rendering.rb:45:in `process'
actionpack (3.2.1) lib/action_controller/metal.rb:203:in `dispatch'
actionpack (3.2.1) lib/action_controller/metal/rack_delegation.rb:14:in `dispatch'
actionpack (3.2.1) lib/action_controller/metal.rb:246:in `block in action'
actionpack (3.2.1) lib/action_dispatch/routing/route_set.rb:66:in `call'
actionpack (3.2.1) lib/action_dispatch/routing/route_set.rb:66:in `dispatch'
actionpack (3.2.1) lib/action_dispatch/routing/route_set.rb:30:in `call'
journey (1.0.3) lib/journey/router.rb:68:in `block 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.1) lib/action_dispatch/routing/route_set.rb:589:in `call'
sass (3.1.15) lib/sass/plugin/rack.rb:54:in `call'
warden (1.1.1) lib/warden/manager.rb:35:in `block in call'
warden (1.1.1) lib/warden/manager.rb:34:in `catch'
warden (1.1.1) lib/warden/manager.rb:34:in `call'
actionpack (3.2.1) 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:35:in `call'
actionpack (3.2.1) lib/action_dispatch/middleware/head.rb:14:in `call'
actionpack (3.2.1) lib/action_dispatch/middleware/params_parser.rb:21:in `call'
actionpack (3.2.1) 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.1) lib/action_dispatch/middleware/cookies.rb:338:in `call'
activerecord (3.2.1) lib/active_record/query_cache.rb:64:in `call'
activerecord (3.2.1) lib/active_record/connection_adapters/abstract/connection_pool.rb:443:in `call'
actionpack (3.2.1) lib/action_dispatch/middleware/callbacks.rb:28:in `block in call'
activesupport (3.2.1) lib/active_support/callbacks.rb:405:in `_run__1039351831__call__833288071__callbacks'
activesupport (3.2.1) lib/active_support/callbacks.rb:405:in `__run_callback'
activesupport (3.2.1) lib/active_support/callbacks.rb:385:in `_run_call_callbacks'
activesupport (3.2.1) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (3.2.1) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (3.2.1) lib/action_dispatch/middleware/reloader.rb:65:in `call'
actionpack (3.2.1) lib/action_dispatch/middleware/remote_ip.rb:31:in `call'
actionpack (3.2.1) lib/action_dispatch/middleware/debug_exceptions.rb:16:in `call'
actionpack (3.2.1) lib/action_dispatch/middleware/show_exceptions.rb:56:in `call'
railties (3.2.1) lib/rails/rack/logger.rb:26:in `call_app'
railties (3.2.1) lib/rails/rack/logger.rb:16:in `call'
actionpack (3.2.1) 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.1) 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.1) lib/action_dispatch/middleware/static.rb:53:in `call'
railties (3.2.1) lib/rails/engine.rb:479:in `call'
railties (3.2.1) lib/rails/application.rb:220:in `call'
railties (3.2.1) lib/rails/railtie/configurable.rb:30:in `method_missing'
/home/led/.passenger/standalone/3.0.11-x86-ruby1.9.3-linux-gcc4.6.3-1002/support/lib/phusion_passenger/rack/request_handler.rb:96:in `process_request'
/home/led/.passenger/standalone/3.0.11-x86-ruby1.9.3-linux-gcc4.6.3-1002/support/lib/phusion_passenger/abstract_request_handler.rb:513:in `accept_and_process_next_request'
/home/led/.passenger/standalone/3.0.11-x86-ruby1.9.3-linux-gcc4.6.3-1002/support/lib/phusion_passenger/abstract_request_handler.rb:274:in `main_loop'
/home/led/.passenger/standalone/3.0.11-x86-ruby1.9.3-linux-gcc4.6.3-1002/support/lib/phusion_passenger/rack/application_spawner.rb:206:in `start_request_handler'
/home/led/.passenger/standalone/3.0.11-x86-ruby1.9.3-linux-gcc4.6.3-1002/support/lib/phusion_passenger/rack/application_spawner.rb:171:in `block in handle_spawn_application'
/home/led/.passenger/standalone/3.0.11-x86-ruby1.9.3-linux-gcc4.6.3-1002/support/lib/phusion_passenger/utils.rb:479:in `safe_fork'
/home/led/.passenger/standalone/3.0.11-x86-ruby1.9.3-linux-gcc4.6.3-1002/support/lib/phusion_passenger/rack/application_spawner.rb:166:in `handle_spawn_application'
/home/led/.passenger/standalone/3.0.11-x86-ruby1.9.3-linux-gcc4.6.3-1002/support/lib/phusion_passenger/abstract_server.rb:357:in `server_main_loop'
/home/led/.passenger/standalone/3.0.11-x86-ruby1.9.3-linux-gcc4.6.3-1002/support/lib/phusion_passenger/abstract_server.rb:206:in `start_synchronously'
/home/led/.passenger/standalone/3.0.11-x86-ruby1.9.3-linux-gcc4.6.3-1002/support/lib/phusion_passenger/abstract_server.rb:180:in `start'
/home/led/.passenger/standalone/3.0.11-x86-ruby1.9.3-linux-gcc4.6.3-1002/support/lib/phusion_passenger/rack/application_spawner.rb:129:in `start'
/home/led/.passenger/standalone/3.0.11-x86-ruby1.9.3-linux-gcc4.6.3-1002/support/lib/phusion_passenger/spawn_manager.rb:253:in `block (2 levels) in spawn_rack_application'
/home/led/.passenger/standalone/3.0.11-x86-ruby1.9.3-linux-gcc4.6.3-1002/support/lib/phusion_passenger/abstract_server_collection.rb:132:in `lookup_or_add'
/home/led/.passenger/standalone/3.0.11-x86-ruby1.9.3-linux-gcc4.6.3-1002/support/lib/phusion_passenger/spawn_manager.rb:246:in `block in spawn_rack_application'
/home/led/.passenger/standalone/3.0.11-x86-ruby1.9.3-linux-gcc4.6.3-1002/support/lib/phusion_passenger/abstract_server_collection.rb:82:in `block in synchronize'
<internal:prelude>:10:in `synchronize'
/home/led/.passenger/standalone/3.0.11-x86-ruby1.9.3-linux-gcc4.6.3-1002/support/lib/phusion_passenger/abstract_server_collection.rb:79:in `synchronize'
/home/led/.passenger/standalone/3.0.11-x86-ruby1.9.3-linux-gcc4.6.3-1002/support/lib/phusion_passenger/spawn_manager.rb:244:in `spawn_rack_application'
/home/led/.passenger/standalone/3.0.11-x86-ruby1.9.3-linux-gcc4.6.3-1002/support/lib/phusion_passenger/spawn_manager.rb:137:in `spawn_application'
/home/led/.passenger/standalone/3.0.11-x86-ruby1.9.3-linux-gcc4.6.3-1002/support/lib/phusion_passenger/spawn_manager.rb:275:in `handle_spawn_application'
/home/led/.passenger/standalone/3.0.11-x86-ruby1.9.3-linux-gcc4.6.3-1002/support/lib/phusion_passenger/abstract_server.rb:357:in `server_main_loop'
/home/led/.passenger/standalone/3.0.11-x86-ruby1.9.3-linux-gcc4.6.3-1002/support/lib/phusion_passenger/abstract_server.rb:206:in `start_synchronously'
/home/led/.passenger/standalone/3.0.11-x86-ruby1.9.3-linux-gcc4.6.3-1002/support/helper-scripts/passenger-spawn-server:99:in `<main>'
What you send :
{
"crew_for_package" => {
"package_id"=>"1",
"crew_id"=>"1",
"quantity"=>"1"
}
}
What you call :
params[:package_crew][:package_id]
params[:package_crew][:crew_id]
You see something wrong? This might not fix your problem, but it should at least send you in the right direction! :-)

Resources