Can anyone explain why I keep getting an error in production but not in development? Relevant parts:
get: /user/logout
ActionController::RoutingError (uninitialized constant User::SessionController):
activesupport/lib/active_support/inflector/methods.rb:229:in `block in constantize'
activesupport/lib/active_support/inflector/methods.rb:228:in `each'
activesupport/lib/active_support/inflector/methods.rb:228:in `constantize'
actionpack/lib/action_dispatch/routing/route_set.rb:69:in `controller_reference'
actionpack/lib/action_dispatch/routing/route_set.rb:54:in `controller'
actionpack/lib/action_dispatch/routing/route_set.rb:32:in `call'
journey/lib/journey/router.rb:68:in `block in call'
journey/lib/journey/router.rb:56:in `each'
journey/lib/journey/router.rb:56:in `call'
actionpack/lib/action_dispatch/routing /route_set.rb:600:in `call'
omniauth/lib/omniauth/strategy.rb:177:in `call!'
omniauth/lib/omniauth/strategy.rb:157:in `call'
omniauth/lib/omniauth/builder.rb:48:in `call'
airbrake/lib/airbrake/rack.rb:27:in `call'
Routes:
Application1::Application.routes.draw do
match('/auth/:provider/callback' => 'session#create', :format => false)
root(:to => 'blog/archives#index', :format => false)
namespace(:user) do
match('/logout' => 'session#destroy', :format => false)
end
namespace(:blog) do
match('/archive/:slug' => 'archive#show', :format => false)
constraints(:page => /page\d+/) do
match('/archives/:page' => 'archives#index', :format => false)
end
end
end
I am using Rails 3.2.3 with the latest Omniauth.
You have created a namespace user and therefore you should place the session controller that defines the destroy action in this path:
/app/controllers/user/session_controller.rb
Then you can do stuff like:
Create a file in /app/controller/user/base_controller.rb that defines this:
class User::BaseController < ApplicationController
# Whatever you want here
end
And define the sessions controller located in /app/controllers/user/session_controller.rb as:
class Users::SessionsController < User::BaseController
def destroy
# whatever you want destroy to do..
end
end
Read this for more documentation about namespaces and routing.
Related
Using Rails 5.2.1,
I am adding a customization possibility to my app which is basically a blog...
The app has a landing page that could be customized, the blog owner could change the images, colors etc...
So I've created a customization controller, model plus uploaders for each images that can be personalised.
Customization has only one instance.
So Locally everything works like a charm.
Rspec fails since I am calling #customization in the landing page...
It's not possible anymore to add or edit images in the Article
rspec failures
Failures:
1) managing article The admin is logged in edit a article text
Failure/Error: raise ActionController::RoutingError, "No route matches [#{env['REQUEST_METHOD']}] #{env['PATH_INFO'].inspect}"
ActionController::RoutingError:
No route matches [GET] "/images/fallback/default.png"
# /Users/bill/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/actionpack-5.2.1/lib/action_dispatch/middleware/debug_exceptions.rb:65:in `call'
# /Users/bill/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/actionpack-5.2.1/lib/action_dispatch/middleware/show_exceptions.rb:33:in `call'
# /Users/bill/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/railties-5.2.1/lib/rails/rack/logger.rb:38:in `call_app'
# /Users/bill/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/railties-5.2.1/lib/rails/rack/logger.rb:26:in `block in call'
# /Users/bill/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/activesupport-5.2.1/lib/active_support/tagged_logging.rb:71:in `block in tagged'
# /Users/bill/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/activesupport-5.2.1/lib/active_support/tagged_logging.rb:28:in `tagged'
# /Users/bill/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/activesupport-5.2.1/lib/active_support/tagged_logging.rb:71:in `tagged'
# /Users/bill/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/railties-5.2.1/lib/rails/rack/logger.rb:26:in `call'
# /Users/bill/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/actionpack-5.2.1/lib/action_dispatch/middleware/remote_ip.rb:81:in `call'
# /Users/bill/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/actionpack-5.2.1/lib/action_dispatch/middleware/request_id.rb:27:in `call'
# /Users/bill/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/rack-2.0.5/lib/rack/method_override.rb:22:in `call'
# /Users/bill/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/rack-2.0.5/lib/rack/runtime.rb:22:in `call'
# /Users/bill/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/activesupport-5.2.1/lib/active_support/cache/strategy/local_cache_middleware.rb:29:in `call'
# /Users/bill/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/actionpack-5.2.1/lib/action_dispatch/middleware/executor.rb:14:in `call'
# /Users/bill/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/actionpack-5.2.1/lib/action_dispatch/middleware/static.rb:127:in `call'
# /Users/bill/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/rack-2.0.5/lib/rack/sendfile.rb:111:in `call'
# /Users/bill/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/railties-5.2.1/lib/rails/engine.rb:524:in `call'
# /Users/bill/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/rack-2.0.5/lib/rack/urlmap.rb:68:in `block in call'
# /Users/bill/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/rack-2.0.5/lib/rack/urlmap.rb:53:in `each'
# /Users/bill/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/rack-2.0.5/lib/rack/urlmap.rb:53:in `call'
# /Users/bill/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/capybara-3.7.2/lib/capybara/server/middleware.rb:48:in `call'
# /Users/bill/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/puma-3.12.0/lib/puma/configuration.rb:225:in `call'
# /Users/bill/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/puma-3.12.0/lib/puma/server.rb:658:in `handle_request'
# /Users/bill/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/puma-3.12.0/lib/puma/server.rb:472:in `process_client'
# /Users/bill/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/puma-3.12.0/lib/puma/server.rb:332:in `block in run'
# /Users/bill/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/puma-3.12.0/lib/puma/thread_pool.rb:133:in `block in spawn_thread'
#
# Showing full backtrace because every line was filtered out.
# See docs for RSpec::Configuration#backtrace_exclusion_patterns and
# RSpec::Configuration#backtrace_inclusion_patterns for more information.
# ------------------
# --- Caused by: ---
# Capybara::CapybaraError:
# Your application server raised an error - It has been raised in your test code because Capybara.raise_server_errors == true
# /Users/bill/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/capybara-3.7.2/lib/capybara/session.rb:144:in `raise_server_error!'
2) managing article The admin is logged in add images for an article
Failure/Error: raise ActionController::RoutingError, "No route matches [#{env['REQUEST_METHOD']}] #{env['PATH_INFO'].inspect}"
ActionController::RoutingError:
No route matches [GET] "/images/fallback/default.png"
# /Users/bill/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/actionpack-5.2.1/lib/action_dispatch/middleware/debug_exceptions.rb:65:in `call'
# /Users/bill/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/actionpack-5.2.1/lib/action_dispatch/middleware/show_exceptions.rb:33:in `call'
# /Users/bill/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/railties-5.2.1/lib/rails/rack/logger.rb:38:in `call_app'
# /Users/bill/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/railties-5.2.1/lib/rails/rack/logger.rb:26:in `block in call'
# /Users/bill/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/activesupport-5.2.1/lib/active_support/tagged_logging.rb:71:in `block in tagged'
# /Users/bill/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/activesupport-5.2.1/lib/active_support/tagged_logging.rb:28:in `tagged'
# /Users/bill/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/activesupport-5.2.1/lib/active_support/tagged_logging.rb:71:in `tagged'
# /Users/bill/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/railties-5.2.1/lib/rails/rack/logger.rb:26:in `call'
# /Users/bill/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/actionpack-5.2.1/lib/action_dispatch/middleware/remote_ip.rb:81:in `call'
# /Users/bill/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/actionpack-5.2.1/lib/action_dispatch/middleware/request_id.rb:27:in `call'
# /Users/bill/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/rack-2.0.5/lib/rack/method_override.rb:22:in `call'
# /Users/bill/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/rack-2.0.5/lib/rack/runtime.rb:22:in `call'
# /Users/bill/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/activesupport-5.2.1/lib/active_support/cache/strategy/local_cache_middleware.rb:29:in `call'
# /Users/bill/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/actionpack-5.2.1/lib/action_dispatch/middleware/executor.rb:14:in `call'
# /Users/bill/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/actionpack-5.2.1/lib/action_dispatch/middleware/static.rb:127:in `call'
# /Users/bill/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/rack-2.0.5/lib/rack/sendfile.rb:111:in `call'
# /Users/bill/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/railties-5.2.1/lib/rails/engine.rb:524:in `call'
# /Users/bill/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/rack-2.0.5/lib/rack/urlmap.rb:68:in `block in call'
# /Users/bill/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/rack-2.0.5/lib/rack/urlmap.rb:53:in `each'
# /Users/bill/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/rack-2.0.5/lib/rack/urlmap.rb:53:in `call'
# /Users/bill/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/capybara-3.7.2/lib/capybara/server/middleware.rb:48:in `call'
# /Users/bill/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/puma-3.12.0/lib/puma/configuration.rb:225:in `call'
# /Users/bill/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/puma-3.12.0/lib/puma/server.rb:658:in `handle_request'
# /Users/bill/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/puma-3.12.0/lib/puma/server.rb:472:in `process_client'
# /Users/bill/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/puma-3.12.0/lib/puma/server.rb:332:in `block in run'
# /Users/bill/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/puma-3.12.0/lib/puma/thread_pool.rb:133:in `block in spawn_thread'
#
# Showing full backtrace because every line was filtered out.
# See docs for RSpec::Configuration#backtrace_exclusion_patterns and
# RSpec::Configuration#backtrace_inclusion_patterns for more information.
# ------------------
# --- Caused by: ---
# Capybara::ElementNotFound:
# Unable to find visible css "#label_uploader_2"
# ./spec/features/managing_article_spec.rb:51:in `block (3 levels) in <top (required)>'
customization_controller.rb
class CustomizationController < ApplicationController
before_action :authorize
def show
#customization = Customization.instance
end
def update
#customization = Customization.instance
if #customization.update(customization_params)
redirect_to customization_path, notice: "Successfully updated"
end
end
private
def customization_params
params.require(:customization).permit(
:main_image,
:first_section_image,
:second_section_image,
:third_section_image,
:menu_color,
:body_color,
:icon_color,
:about,
:avatar
)
end
end
customization.rb
class Customization < ApplicationRecord
mount_uploader :avatar, AvatarUploader
mount_uploader :main_image, MainImageUploader
mount_uploader :first_section_image, FirstSectionImageUploader
mount_uploader :second_section_image, SecondSectionImageUploader
mount_uploader :third_section_image, ThirdSectionImageUploader
INSTANCE_ID = 87
def self.instance
Customization.find_or_create_by(id: INSTANCE_ID)
end
end
the uploader
class ThirdSectionImageUploader < CarrierWave::Uploader::Base
include CarrierWave::MiniMagick
storage :file
if Rails.env.production?
storage :fog
else
storage :file
end
version :thumb do
process resize_to_fill: [280, 280]
end
def default_url(*args)
"/images/fallback/" + [version_name, "default.png"].compact.join('_')
end
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
def extension_white_list
%w(jpg jpeg gif png)
end
end
home_controller.rb
class HomeController < ApplicationController
def index
#customization = Customization.instance
end
end
home/index.html.rb - aka landing page
<%= link_to videos_path do %>
<figure class="figure">
<%= image_tag(#customization.third_section_image_url.present? ? #customization.third_section_image_url : "https://s3-eu-west-1.amazonaws.com/beehappy/images_site/bibi.jpg", class: 'figure-img img-fluid') %>
<figcaption class="figure-caption text-gold">Media</figcaption>
</figure>
<% end %>
UPDATE
articles_spec.rb
require "rails_helper"
RSpec.feature "managing articles" do
fixtures :articles, :user
context "The admin is logged in" do
before :each do
login_as :admin
end
scenario "edit an article text", :js do
guitar = articles(:fender)
visit article_path(guitar)
find(".edit_link").click
fill_in "article[title]", with: "Fender Telecaster"
click_on "Update Me"
expect(page).to have_content("Article was successfully updated")
end
scenario "add images for a guitar" do
guitar = articles(:gibson)
visit article_path(guitar)
find(".edit_link").click
click_on "Add pictures"
within "#label_uploader_2" do
within "#span_uploader_2" do
attach_file("article[attachments][]" , Rails.root.join("spec/assets/images/img_2.jpg"))
end
end
click_on "Update"
expect(page).to have_content("Successfully added")
end
end
end
The actual error is No route matches [GET] "/images/fallback/default.png". You are setting a default path on your carrierwave uploader but it looks like the image is missing. Where's that image? for that route to work it should be in /public/images/fallback/default.png
I have a resource called "parameters" that is nested under "tests" in my API. There relation is as follows: "A test has many parameters". I've structured my routes as follows
tests/:test_id/parameters/:parameter_id
and my rake routes gives:
test_parameters GET /tests/:test_id/parameters(.:format) parameters#index {:format=>:json}
POST /tests/:test_id/parameters(.:format) parameters#create {:format=>:json}
new_test_parameter GET /tests/:test_id/parameters/new(.:format) parameters#new {:format=>:json}
edit_test_parameter GET /tests/:test_id/parameters/:id/edit(.:format) parameters#edit {:format=>:json}
test_parameter GET /tests/:test_id/parameters/:id(.:format) parameters#show {:format=>:json}
PATCH /tests/:test_id/parameters/:id(.:format) parameters#update {:format=>:json}
PUT /tests/:test_id/parameters/:id(.:format) parameters#update {:format=>:json}
DELETE /tests/:test_id/parameters/:id(.:format) parameters#destroy {:format=>:json}
I'm writing simple rspec tests to test all the typical actions of my API. Right now, my POST/CREATE is giving me a very puzzling error.
Failures:
1) ParametersController POST create a new parameter with valid attributes successfully with name and times
Failure/Error: post :create, :test_id => #test.id, parameter: parameter.attributes, format: :json
NoMethodError:
undefined method `parameter_url' for #<ParametersController:0x000001072b4280>
# /Users/naseem.alnaji/.rvm/gems/ruby-2.1.1/gems/actionpack-4.2.2/lib/action_dispatch/routing/polymorphic_routes.rb:220:in `polymorphic_method'
# /Users/naseem.alnaji/.rvm/gems/ruby-2.1.1/gems/actionpack-4.2.2/lib/action_dispatch/routing/polymorphic_routes.rb:114:in `polymorphic_url'
# /Users/naseem.alnaji/.rvm/gems/ruby-2.1.1/gems/actionpack-4.2.2/lib/action_dispatch/routing/url_for.rb:163:in `url_for'
# /Users/naseem.alnaji/.rvm/gems/ruby-2.1.1/gems/actionpack-4.2.2/lib/action_controller/metal/rendering.rb:95:in `_process_options'
# /Users/naseem.alnaji/.rvm/gems/ruby-2.1.1/gems/actionpack-4.2.2/lib/action_controller/metal/streaming.rb:200:in `_process_options'
# /Users/naseem.alnaji/.rvm/gems/ruby-2.1.1/gems/actionpack-4.2.2/lib/action_controller/metal/renderers.rb:43:in `block in _render_to_body_with_renderer'
# /Users/naseem.alnaji/.rvm/gems/ruby-2.1.1/gems/actionpack-4.2.2/lib/action_controller/metal/renderers.rb:41:in `_render_to_body_with_renderer'
# /Users/naseem.alnaji/.rvm/gems/ruby-2.1.1/gems/actionpack-4.2.2/lib/action_controller/metal/renderers.rb:37:in `render_to_body'
# /Users/naseem.alnaji/.rvm/gems/ruby-2.1.1/gems/actionpack-4.2.2/lib/abstract_controller/rendering.rb:25:in `render'
# /Users/naseem.alnaji/.rvm/gems/ruby-2.1.1/gems/actionpack-4.2.2/lib/action_controller/metal/rendering.rb:16:in `render'
# /Users/naseem.alnaji/.rvm/gems/ruby-2.1.1/gems/actionpack-4.2.2/lib/action_controller/metal/instrumentation.rb:44:in `block (2 levels) in render'
# /Users/naseem.alnaji/.rvm/gems/ruby-2.1.1/gems/activesupport-4.2.2/lib/active_support/core_ext/benchmark.rb:12:in `block in ms'
# /Users/naseem.alnaji/.rvm/gems/ruby-2.1.1/gems/activesupport-4.2.2/lib/active_support/core_ext/benchmark.rb:12:in `ms'
# /Users/naseem.alnaji/.rvm/gems/ruby-2.1.1/gems/actionpack-4.2.2/lib/action_controller/metal/instrumentation.rb:44:in `block in render'
# /Users/naseem.alnaji/.rvm/gems/ruby-2.1.1/gems/actionpack-4.2.2/lib/action_controller/metal/instrumentation.rb:87:in `cleanup_view_runtime'
# /Users/naseem.alnaji/.rvm/gems/ruby-2.1.1/gems/activerecord-4.2.2/lib/active_record/railties/controller_runtime.rb:25:in `cleanup_view_runtime'
# /Users/naseem.alnaji/.rvm/gems/ruby-2.1.1/gems/actionpack-4.2.2/lib/action_controller/metal/instrumentation.rb:43:in `render'
# /Users/naseem.alnaji/.rvm/gems/ruby-2.1.1/gems/responders-2.1.0/lib/action_controller/responder.rb:258:in `display'
# /Users/naseem.alnaji/.rvm/gems/ruby-2.1.1/gems/responders-2.1.0/lib/action_controller/responder.rb:214:in `api_behavior'
# /Users/naseem.alnaji/.rvm/gems/ruby-2.1.1/gems/responders-2.1.0/lib/action_controller/responder.rb:191:in `rescue in to_format'
# /Users/naseem.alnaji/.rvm/gems/ruby-2.1.1/gems/responders-2.1.0/lib/action_controller/responder.rb:185:in `to_format'
# /Users/naseem.alnaji/.rvm/gems/ruby-2.1.1/gems/responders-2.1.0/lib/action_controller/responder.rb:163:in `respond'
# /Users/naseem.alnaji/.rvm/gems/ruby-2.1.1/gems/responders-2.1.0/lib/action_controller/responder.rb:156:in `call'
# /Users/naseem.alnaji/.rvm/gems/ruby-2.1.1/gems/responders-2.1.0/lib/action_controller/respond_with.rb:203:in `respond_with'
# ./app/controllers/parameters_controller.rb:13:in `create'
# /Users/naseem.alnaji/.rvm/gems/ruby-2.1.1/gems/actionpack-4.2.2/lib/action_controller/metal/implicit_render.rb:4:in `send_action'
# /Users/naseem.alnaji/.rvm/gems/ruby-2.1.1/gems/actionpack-4.2.2/lib/abstract_controller/base.rb:198:in `process_action'
# /Users/naseem.alnaji/.rvm/gems/ruby-2.1.1/gems/actionpack-4.2.2/lib/action_controller/metal/rendering.rb:10:in `process_action'
# /Users/naseem.alnaji/.rvm/gems/ruby-2.1.1/gems/actionpack-4.2.2/lib/abstract_controller/callbacks.rb:20:in `block in process_action'
# /Users/naseem.alnaji/.rvm/gems/ruby-2.1.1/gems/activesupport-4.2.2/lib/active_support/callbacks.rb:117:in `call'
# /Users/naseem.alnaji/.rvm/gems/ruby-2.1.1/gems/activesupport-4.2.2/lib/active_support/callbacks.rb:117:in `call'
# /Users/naseem.alnaji/.rvm/gems/ruby-2.1.1/gems/activesupport-4.2.2/lib/active_support/callbacks.rb:555:in `block (2 levels) in compile'
# /Users/naseem.alnaji/.rvm/gems/ruby-2.1.1/gems/activesupport-4.2.2/lib/active_support/callbacks.rb:505:in `call'
# /Users/naseem.alnaji/.rvm/gems/ruby-2.1.1/gems/activesupport-4.2.2/lib/active_support/callbacks.rb:505:in `call'
# /Users/naseem.alnaji/.rvm/gems/ruby-2.1.1/gems/activesupport-4.2.2/lib/active_support/callbacks.rb:92:in `_run_callbacks'
# /Users/naseem.alnaji/.rvm/gems/ruby-2.1.1/gems/activesupport-4.2.2/lib/active_support/callbacks.rb:776:in `_run_process_action_callbacks'
# /Users/naseem.alnaji/.rvm/gems/ruby-2.1.1/gems/activesupport-4.2.2/lib/active_support/callbacks.rb:81:in `run_callbacks'
# /Users/naseem.alnaji/.rvm/gems/ruby-2.1.1/gems/actionpack-4.2.2/lib/abstract_controller/callbacks.rb:19:in `process_action'
# /Users/naseem.alnaji/.rvm/gems/ruby-2.1.1/gems/actionpack-4.2.2/lib/action_controller/metal/rescue.rb:29:in `process_action'
# /Users/naseem.alnaji/.rvm/gems/ruby-2.1.1/gems/actionpack-4.2.2/lib/action_controller/metal/instrumentation.rb:32:in `block in process_action'
# /Users/naseem.alnaji/.rvm/gems/ruby-2.1.1/gems/activesupport-4.2.2/lib/active_support/notifications.rb:164:in `block in instrument'
# /Users/naseem.alnaji/.rvm/gems/ruby-2.1.1/gems/activesupport-4.2.2/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
# /Users/naseem.alnaji/.rvm/gems/ruby-2.1.1/gems/activesupport-4.2.2/lib/active_support/notifications.rb:164:in `instrument'
# /Users/naseem.alnaji/.rvm/gems/ruby-2.1.1/gems/actionpack-4.2.2/lib/action_controller/metal/instrumentation.rb:30:in `process_action'
# /Users/naseem.alnaji/.rvm/gems/ruby-2.1.1/gems/actionpack-4.2.2/lib/action_controller/metal/params_wrapper.rb:250:in `process_action'
# /Users/naseem.alnaji/.rvm/gems/ruby-2.1.1/gems/activerecord-4.2.2/lib/active_record/railties/controller_runtime.rb:18:in `process_action'
# /Users/naseem.alnaji/.rvm/gems/ruby-2.1.1/gems/actionpack-4.2.2/lib/abstract_controller/base.rb:137:in `process'
# /Users/naseem.alnaji/.rvm/gems/ruby-2.1.1/gems/actionview-4.2.2/lib/action_view/rendering.rb:30:in `process'
# /Users/naseem.alnaji/.rvm/gems/ruby-2.1.1/gems/actionpack-4.2.2/lib/action_controller/test_case.rb:632:in `process'
# /Users/naseem.alnaji/.rvm/gems/ruby-2.1.1/gems/actionpack-4.2.2/lib/action_controller/test_case.rb:65:in `process'
# /Users/naseem.alnaji/.rvm/gems/ruby-2.1.1/gems/actionpack-4.2.2/lib/action_controller/test_case.rb:514:in `post'
# ./spec/controllers/parameters_controller_spec.rb:34:in `block (5 levels) in <top (required)>'
# ./spec/controllers/parameters_controller_spec.rb:33:in `block (4 levels) in <top (required)>'
I've tried changing the formats in how I'm submitting the POST but that hadn't changed anything. For now, my rspec test looks like this:
"spec/controllers/parameters_controller_spec.rb"
require 'spec_helper'
describe ParametersController do
before :each do
#test = FactoryGirl.create(:test, id: 1, name: 'Eccentric Tech')
#test.save
end
# ...
describe 'POST create a new parameter' do
context 'with valid attributes' do
it 'successfully with name and times' do
parameter = FactoryGirl.build(:parameter)
expect {
post :create, :test_id => #test.id, parameter: parameter.attributes, format: :json
}.to change(Parameter, :count).by(1)
end
end
context 'with invalid attributes' do
it 'fails without a name' do
parameter = FactoryGirl.build(:no_name_parameter)
expect {
post :create, :test_id => #test.id, parameter: parameter.attributes, format: :json
}.to change(Parameter, :count).by(0)
end
it 'fails without belonging to a test' do
parameter = FactoryGirl.build(:no_test_parameter)
expect {
post :create, :test_id => #test.id, parameter: parameter.attributes, format: :json
}.to change(Parameter, :count).by(0)
end
end
end
# ...
end
My Factory:
"spec/factories/parameters.rb"
require 'faker'
FactoryGirl.define do
factory :parameter do |f|
f.name { "#{Faker::Hacker.noun}" }
f.value { Faker::Number.number(2) }
f.test_id { 1 }
end
factory :no_name_parameter, parent: :parameter do |f|
f.name nil
f.value { Faker::Number.number(2) }
f.test_id { 1 }
end
factory :no_test_parameter, parent: :parameter do |f|
f.name { "#{Faker::Hacker.noun}" }
f.value { Faker::Number.number(2) }
f.test_id nil
end
end
And finally, my controller:
class ParametersController < ApplicationController
respond_to :json
def index
respond_with Parameter.all
end
def show
respond_with Parameter.find(params[:id])
end
def create
respond_with Parameter.create(parameter_params)
end
def update
respond_with Parameter.update(params[:id], parameter_params)
end
def destroy
respond_with Parameter.destroy(params[:id])
end
private
def parameter_params
params.require(:parameter).permit(:name, :value, :test_id)
end
end
routes.rb:
Rails.application.routes.draw do
scope :defaults => { :format => :json } do
resources :services do
resources :tests
end
resources :tests do
resources :parameters
resources :singular_results
resources :dataset_results
end
end
end
I solved this myself but I have nooooo idea why it works. If someone could explain it please do :)
All I did was make this small change to my controller:
def create
respond_with Parameter.create(parameter_params), location: nil
end
Found a good explanation: Rails: NoMethodError (Undefined method _url for _controller. I can't seem to respond_with json properly after my create. Why?
I created a session_controller to handle token authentication, but I got this error:
Started POST "/users/sign_in" for 127.0.0.1 at 2013-04-29 20:29:44 +0200
Processing by SessionsController#create as */*
Parameters: {"user_login"=>{"login"=>"admin#example.com.", "password"=>"[FILTERED]"}}
Completed 500 Internal Server Error in 1ms
ArgumentError (wrong number of arguments (2 for 1)):
activerecord (3.2.13) lib/active_record/attribute_methods.rb:24:in `[]'
.../bundler/gems/devise-dceb788c6b53/lib/devise.rb:436:in `block (2 levels) in configure_warden!'
warden (1.2.1) lib/warden/session_serializer.rb:35:in `fetch'
warden (1.2.1) lib/warden/proxy.rb:212:in `user'
warden (1.2.1) lib/warden/proxy.rb:318:in `_perform_authentication'
warden (1.2.1) lib/warden/proxy.rb:104:in `authenticate'
warden (1.2.1) lib/warden/proxy.rb:114:in `authenticate?'
.../bundler/gems/devise-dceb788c6b53/app/controllers/devise_controller.rb:124:in `require_no_authentication'
My controller looks like:
class SessionsController < DeviseController
before_filter :ensure_params_exist
respond_to :json
def create
build_resource
resource = User.find_for_database_authentication(:email => params[:user_login][:login])
return invalid_login_attempt unless resource
if resource.valid_password?(params[:user_login][:password])
sign_in("user", resource)
render :json => {:success => true, :auth_token => resource.authentication_token, :email => resource.email}
return
end
invalid_login_attempt
end
And my route file:
devise_for :users, :controllers => {:sessions => "sessions"}
Whats wrong?
Your class declaration does not match Devise namespace:
class SessionsController < Devise::SessionsController
I'm trying to send mail in a Rails 3 application using collectiveidea's delayed_job. If I try to send mail regularly (.deliver) it works fine, but as soon as I switch to delayed job, things fall to pieces.
The standard error I get in the delayed_job mysql table is:
{undefined method `name' for
nil:NilClass...
where 'name' is the first argument in the mailer's view (#contact.name). This works fine if I take delayed_job out again.
If I remove all references to #contact in the view, I get
{A sender (Return-Path, Sender or
From) required to send a message
In short, it doesn't seem to be understanding any arguments at all.
All relevant code below - if anyone has any suggestions for this it would be very appreciated
CONTROLLER
def sendmail
#contact = Contact.new(params[:contact])
if #contact.save
ContactMailer.delay.contact_mail(#contact)
flash[:notice] = 'Your message has been successfully sent'
redirect_to root_path
else
render :action => 'index'
end
end
MAILER:
class ContactMailer < ActionMailer::Base
default :from => "my#email.address"
def contact_mail(contact)
#contact = contact
mail(:to => 'my#email.address', :subject => 'Contact Form Query', :from => 'my#email.address', :content_type => 'text/plain')
end
handle_asynchronously :contact_mail, :run_at => Proc.new { 2.seconds.from_now }
end
MAILER VIEW:
You have received a new query:
-----------------------------------
<%= #contact.name %>
<%= #contact.business %>
<%= #contact.phone %>
-----------------------
<%= #contact.message %>
-----------------------
INITIALIZER:
Delayed::Worker.destroy_failed_jobs = false
Delayed::Worker.max_run_time = 5.weeks
And finally, the full error message:
{undefined method `name' for nil:NilClass
/Users/john/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.0.0/lib/active_support/whiny_nil.rb:48:in `method_missing'
/Users/john/Websites/Rails/InDevelopment/connectted/app/views/contact_mailer/contact_mail.html.erb:4:in `_app_views_contact_mailer_contact_mail_html_erb___3386534441642202773_2166008980__4301703149293725172'
/Users/john/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-3.0.0/lib/action_view/template.rb:135:in `block in render'
/Users/john/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.0.0/lib/active_support/notifications.rb:54:in `instrument'
/Users/john/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-3.0.0/lib/action_view/template.rb:127:in `render'
/Users/john/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-3.0.0/lib/action_view/render/rendering.rb:59:in `block in _render_template'
/Users/john/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.0.0/lib/active_support/notifications.rb:52:in `block in instrument'
/Users/john/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.0.0/lib/active_support/notifications/instrumenter.rb:21:in `instrument'
/Users/john/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.0.0/lib/active_support/notifications.rb:52:in `instrument'
/Users/john/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-3.0.0/lib/action_view/render/rendering.rb:56:in `_render_template'
/Users/john/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-3.0.0/lib/action_view/render/rendering.rb:26:in `render'
/Users/john/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-3.0.0/lib/abstract_controller/rendering.rb:114:in `_render_template'
/Users/john/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-3.0.0/lib/abstract_controller/rendering.rb:108:in `render_to_body'
/Users/john/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-3.0.0/lib/abstract_controller/rendering.rb:101:in `render_to_string'
/Users/john/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-3.0.0/lib/abstract_controller/rendering.rb:92:in `render'
/Users/john/.rvm/gems/ruby-1.9.2-p0/gems/actionmailer-3.0.0/lib/action_mailer/deprecated_api.rb:111:in `render'
/Users/john/.rvm/gems/ruby-1.9.2-p0/gems/actionmailer-3.0.0/lib/action_mailer/old_api.rb:210:in `block in create_parts'
/Users/john/.rvm/gems/ruby-1.9.2-p0/gems/actionmailer-3.0.0/lib/action_mailer/old_api.rb:208:in `each'
/Users/john/.rvm/gems/ruby-1.9.2-p0/gems/actionmailer-3.0.0/lib/action_mailer/old_api.rb:208:in `create_parts'
/Users/john/.rvm/gems/ruby-1.9.2-p0/gems/actionmailer-3.0.0/lib/action_mailer/deprecated_api.rb:143:in `create_parts'
/Users/john/.rvm/gems/ruby-1.9.2-p0/gems/actionmailer-3.0.0/lib/action_mailer/old_api.rb:77:in `process'
/Users/john/.rvm/gems/ruby-1.9.2-p0/gems/actionmailer-3.0.0/lib/action_mailer/base.rb:446:in `process'
/Users/john/.rvm/gems/ruby-1.9.2-p0/gems/actionmailer-3.0.0/lib/action_mailer/base.rb:441:in `initialize'
/Users/john/.rvm/gems/ruby-1.9.2-p0/gems/actionmailer-3.0.0/lib/action_mailer/base.rb:425:in `new'
/Users/john/.rvm/gems/ruby-1.9.2-p0/gems/actionmailer-3.0.0/lib/action_mailer/base.rb:425:in `method_missing'
/Users/john/.rvm/gems/ruby-1.9.2-p0/bundler/gems/delayed_job-c933ffcd776a/lib/delayed/performable_mailer.rb:6:in `perform'
/Users/john/.rvm/gems/ruby-1.9.2-p0/bundler/gems/delayed_job-c933ffcd776a/lib/delayed/backend/base.rb:83:in `invoke_job'
/Users/john/.rvm/gems/ruby-1.9.2-p0/bundler/gems/delayed_job-c933ffcd776a/lib/delayed/worker.rb:119:in `block (2 levels) in run'
/Users/john/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/timeout.rb:57:in `timeout'
/Users/john/.rvm/gems/ruby-1.9.2-p0/bundler/gems/delayed_job-c933ffcd776a/lib/delayed
/worker.rb:119:in `block in run'
/Users/john/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/benchmark.rb:309:in `realtime'
/Users/john/.rvm/gems/ruby-1.9.2-p0/bundler/gems/delayed_job-c933ffcd776a/lib/delayed/worker.rb:118:in `run'
/Users/john/.rvm/gems/ruby-1.9.2-p0/bundler/gems/delayed_job-c933ffcd776a/lib/delayed/worker.rb:176:in `reserve_and_run_one_job'
/Users/john/.rvm/gems/ruby-1.9.2-p0/bundler/gems/delayed_job-c933ffcd776a/lib/delayed/worker.rb:103:in `block in work_off'
/Users/john/.rvm/gems/ruby-1.9.2-p0/bundler/gems/delayed_job-c933ffcd776a/lib/delayed/worker.rb:102:in `times'
/Users/john/.rvm/gems/ruby-1.9.2-p0/bundler/gems/delayed_job-c933ffcd776a/lib/delayed/worker.rb:102:in `work_off'
/Users/john/.rvm/gems/ruby-1.9.2-p0/bundler/gems/delayed_job-c933ffcd776a/lib/delayed/worker.rb:77:in `block (2 levels) in start'
/Users/john/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/benchmark.rb:309:in `realtime'
/Users/john/.rvm/gems/ruby-1.9.2-p0/bundler/gems/delayed_job-c933ffcd776a/lib/delayed/worker.rb:76:in `block in start'
/Users/john/.rvm/gems/ruby-1.9.2-p0/bundler/gems/delayed_job-c933ffcd776a/lib/delayed/worker.rb:73:in `loop'
/Users/john/.rvm/gems/ruby-1.9.2-p0/bundler/gems/delayed_job-c933ffcd776a/lib/delayed/worker.rb:73:in `start'
/Users/john/.rvm/gems/ruby-1.9.2-p0/bundler/gems/delayed_job-c933ffcd776a/lib/delayed/command.rb:100:in `run'
/Users/john/.rvm/gems/ruby-1.9.2-p0/bundler/gems/delayed_job-c933ffcd776a/lib/delayed/command.rb:79:in `block in run_process'
/Users/john/.rvm/gems/ruby-1.9.2-p0/gems/daemons-1.1.0/lib/daemons/application.rb:250:in `call'
/Users/john/.rvm/gems/ruby-1.9.2-p0/gems/daemons-1.1.0/lib/daemons/application.rb:250:in `block in start_proc'
/Users/john/.rvm/gems/ruby-1.9.2-p0/gems/daemons-1.1.0/lib/daemons/daemonize.rb:199:in `call'
/Users/john/.rvm/gems/ruby-1.9.2-p0/gems/daemons-1.1.0/lib/daemons/daemonize.rb:199:in `call_as_daemon'
/Users/john/.rvm/gems/ruby-1.9.2-p0/gems/daemons-1.1.0/lib/daemons/application.rb:254:in `start_proc'
/Users/john/.rvm/gems/ruby-1.9.2-p0/gems/daemons-1.1.0/lib/daemons/application.rb:294:in `start'
/Users/john/.rvm/gems/ruby-1.9.2-p0/gems/daemons-1.1.0/lib/daemons/controller.rb:70:in `run'
/Users/john/.rvm/gems/ruby-1.9.2-p0/gems/daemons-1.1.0/lib/daemons.rb:193:in `block in run_proc'
/Users/john/.rvm/gems/ruby-1.9.2-p0/gems/daemons-1.1.0/lib/daemons/cmdline.rb:112:in `call'
/Users/john/.rvm/gems/ruby-1.9.2-p0/gems/daemons-1.1.0/lib/daemons/cmdline.rb:112:in `catch_exceptions'
/Users/john/.rvm/gems/ruby-1.9.2-p0/gems/daemons-1.1.0/lib/daemons.rb:192:in `run_proc'
/Users/john/.rvm/gems/ruby-1.9.2-p0/bundler/gems/delayed_job-c933ffcd776a/lib/delayed/command.rb:78:in `run_process'
/Users/john/.rvm/gems/ruby-1.9.2-p0/bundler/gems/delayed_job-c933ffcd776a/lib/delayed/command.rb:72:in `block in daemonize'
/Users/john/.rvm/gems/ruby-1.9.2-p0/bundler/gems/delayed_job-c933ffcd776a/lib/delayed/command.rb:70:in `times'
/Users/john/.rvm/gems/ruby-1.9.2-p0/bundler/gems/delayed_job-c933ffcd776a/lib/delayed/command.rb:70:in `daemonize'
script/delayed_job:5:in `<main>' |
The issue is with the code in your mailer taking the object instead of the objects id:
def contact_mail(contact)
#contact = contact
mail(:to => 'my#email.address', :subject => 'Contact Form Query', :from => 'my#email.address', :content_type => 'text/plain')
end
You should change that to this:
def contact_mail(contact_id)
#contact = Contact.find(contact_id)
mail(:to => 'my#email.address', :subject => 'Contact Form Query', :from => 'my#email.address', :content_type => 'text/plain')
end
Never pass the actual objects to your mailer. Simply pass the id's and retrieve them upon processing.
I had this same problem, and fixed it by moving all the attributes into instance variables. So, in the view:
<%= #contact.name %>
<%= #contact.business %>
<%= #contact.phone %>
becomes:
<%= #name %>
<%= #business %>
<%= #phone %>
and I just looked up the instance variables in the mailer method. So, in the mailer:
def contact_mail(contact)
#contact = contact
mail(:to => 'my#email.address', :subject => 'Contact Form Query', :from => 'my#email.address', :content_type => 'text/plain')
end
becomes:
def contact_mail(contact)
#name = contact.name
#business = contact.business
#phone = contact.phone
mail(:to => 'my#email.address', :subject => 'Contact Form Query', :from => 'my#email.address', :content_type => 'text/plain')
end
Why is it not working? Not sure, I imagine it has to do with some ActionMailer voodoo.
How to get it working? Abstract out the delayed job pieces into another class. Have the method that is delayed do nothing more than send them email; meaning that the rendering of the email is done in real time, but the sending of it is delayed. This should get around your problem and accomplish the asynchronous sending of emails.
Hey this might be far off, but you're not sending any params to your MAILER. Here's a copy of my referred_email.rb I keep in my lib/ dir. I call it with delayed_job:
#my controller
Delayed::Job.enqueue ReferredEmail.new(params[:subject], params[:editor1])
#Reffered_Email.rb
class ReferredEmail < Struct.new(:subject, :editor1)
def perform
(CardReferral.all.map(&:email) - CardSignup.all.map(&:email)).each do |cf|
#cf = CardReferral.find_by_email(cf)
Notifier.deliver_referred_magic_email(User.find(#cf.user_id), #cf.email, #cf.name, #cf.message, subject, editor1)
end
end
end
It seems like you are using both:
ContactMailer.delay.contact_mail(#contact)
and
handle_asynchronously :contact_mail, :run_at => Proc.new { 2.seconds.from_now }
which you should only do one or the other. Try removing the handle_asynchronously and see if that fixes the problem.
New to rails, and I've just spent hours trying to hunt down a bug. Any help very appreciated.
I'm trying to make a rails page so that if a user enters /info/who_bought/1 the page outputs HTML, and if they enter /info/who_bought/1.xml, the page returns an XML file. (In short, I'm doing chapter 11 from the 'Agile Web Development with Rails' book)
The HTML-formatted output works fine, but if I enter the xml I consistently get a 'wrong number of arguments (1 for 0)' error page. Downloaded the actual ebook and did a direct copy/paste of all code; still facing the same problem. Google doesn't bring up any mention of code bugs.
Code & full stack trace below. If anyone has any ideas I'd be very appreciative. In short - what could possible cause xml.builder to return a '1 for 0 arguments' bug?
Many thanks,
Baggage
# app/controllers/info_controller.rb
class InfoController < ApplicationController
def who_bought
#product = Product.find(params[:id])
#orders = #product.orders
respond_to do |format|
format.html
format.xml {render :layout => false }
end
end
protected
def authorize
end
end
# app/views/info/who_bought.xml.builder
xml.order_list(:for_product => #product.title) do
for o in #orders
xml.order do
xml.name(o.name)
xml.email(o.email)
end
end
end
# app/models/product.rb
class Product < ActiveRecord::Base
has_many :orders, :through => :line_items
has_many :line_items
validates_presence_of :title, :description, :image_url
validates_numericality_of :price
validates_uniqueness_of :title
validates_length_of :title,
:minimum => 10
validates_format_of :image_url,
:with => %r{\.(gif|jpg|png)$}i,
:message => 'must be a URL for GIF, JPG ' +
'or PNG image.'
validate :price_must_be_at_least_a_cent
def price_must_be_at_least_a_cent
errors.add(:price, 'should be at least 0.01') if price.nil? || price < 0.01
end
def self.find_products_for_sale
find(:all, :order => "title")
end
end
# config/routes.rb
ActionController::Routing::Routes.draw do |map|
map.resources :users
map.resources :line_items
map.resources :orders
map.resources :products
map.connect ':controller/:action'
map.connect ':controller/:action/:id'
map.connect ':controller/:action/:id.:format'
end
# Full trace
/usr/lib/ruby/1.8/builder/xmlbase.rb:134:in `to_xs'
/usr/lib/ruby/1.8/builder/xmlbase.rb:134:in `_escape'
/usr/lib/ruby/1.8/builder/xmlbase.rb:87:in `text!'
/usr/lib/ruby/1.8/builder/xmlbase.rb:144:in `_newline'
/usr/lib/ruby/1.8/builder/xmlbase.rb:60:in `method_missing'
app/views/info/who_bought.xml.builder:2
vendor/rails/activerecord/lib/active_record/associations/association_collection.rb:359:in `method_missing'
vendor/rails/activerecord/lib/active_record/associations/association_proxy.rb:212:in `method_missing'
vendor/rails/activerecord/lib/active_record/associations/association_proxy.rb:212:in `each'
vendor/rails/activerecord/lib/active_record/associations/association_proxy.rb:212:in `send'
vendor/rails/activerecord/lib/active_record/associations/association_proxy.rb:212:in `method_missing'
vendor/rails/activerecord/lib/active_record/associations/association_collection.rb:359:in `method_missing'
app/views/info/who_bought.xml.builder:1
vendor/rails/actionpack/lib/action_view/renderable.rb:39:in `send'
vendor/rails/actionpack/lib/action_view/renderable.rb:39:in `render'
vendor/rails/actionpack/lib/action_view/template.rb:73:in `render_template'
vendor/rails/actionpack/lib/action_view/base.rb:256:in `render'
vendor/rails/actionpack/lib/action_controller/base.rb:1177:in `render_for_file'
vendor/rails/actionpack/lib/action_controller/base.rb:940:in `render_without_benchmark'
vendor/rails/actionpack/lib/action_controller/benchmarking.rb:51:in `render'
vendor/rails/activesupport/lib/active_support/core_ext/benchmark.rb:8:in `realtime'
vendor/rails/actionpack/lib/action_controller/benchmarking.rb:51:in `render'
app/controllers/info_controller.rb:6
vendor/rails/actionpack/lib/action_controller/mime_responds.rb:135:in `call'
vendor/rails/actionpack/lib/action_controller/mime_responds.rb:135
vendor/rails/actionpack/lib/action_controller/mime_responds.rb:164:in `call'
vendor/rails/actionpack/lib/action_controller/mime_responds.rb:164:in `respond'
vendor/rails/actionpack/lib/action_controller/mime_responds.rb:158:in `each'
vendor/rails/actionpack/lib/action_controller/mime_responds.rb:158:in `respond'
vendor/rails/actionpack/lib/action_controller/mime_responds.rb:107:in `respond_to'
app/controllers/info_controller.rb:5:in `who_bought'
vendor/rails/actionpack/lib/action_controller/base.rb:1256:in `send'
vendor/rails/actionpack/lib/action_controller/base.rb:1256:in `perform_action_without_filters'
vendor/rails/actionpack/lib/action_controller/filters.rb:617:in `call_filters'
vendor/rails/actionpack/lib/action_controller/filters.rb:610:in `perform_action_without_benchmark'
vendor/rails/actionpack/lib/action_controller/benchmarking.rb:68:in `perform_action_without_rescue'
/usr/lib/ruby/1.8/benchmark.rb:293:in `measure'
vendor/rails/actionpack/lib/action_controller/benchmarking.rb:68:in `perform_action_without_rescue'
vendor/rails/actionpack/lib/action_controller/rescue.rb:136:in `perform_action_without_caching'
vendor/rails/actionpack/lib/action_controller/caching/sql_cache.rb:13:in `perform_action'
vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb:34:in `cache'
vendor/rails/activerecord/lib/active_record/query_cache.rb:8:in `cache'
vendor/rails/actionpack/lib/action_controller/caching/sql_cache.rb:12:in `perform_action'
vendor/rails/actionpack/lib/action_controller/base.rb:524:in `send'
vendor/rails/actionpack/lib/action_controller/base.rb:524:in `process_without_filters'
vendor/rails/actionpack/lib/action_controller/filters.rb:606:in `process_without_session_management_support'
vendor/rails/actionpack/lib/action_controller/session_management.rb:134:in `process'
vendor/rails/actionpack/lib/action_controller/base.rb:392:in `process'
vendor/rails/actionpack/lib/action_controller/dispatcher.rb:184:in `handle_request'
vendor/rails/actionpack/lib/action_controller/dispatcher.rb:112:in `dispatch_unlocked'
vendor/rails/actionpack/lib/action_controller/dispatcher.rb:125:in `dispatch'
vendor/rails/actionpack/lib/action_controller/dispatcher.rb:124:in `synchronize'
vendor/rails/actionpack/lib/action_controller/dispatcher.rb:124:in `dispatch'
vendor/rails/actionpack/lib/action_controller/dispatcher.rb:134:in `dispatch_cgi'
vendor/rails/actionpack/lib/action_controller/dispatcher.rb:41:in `dispatch'
/usr/lib/ruby/1.8/mongrel/rails.rb:76:in `process'
/usr/lib/ruby/1.8/mongrel/rails.rb:74:in `synchronize'
/usr/lib/ruby/1.8/mongrel/rails.rb:74:in `process'
/usr/lib/ruby/1.8/mongrel.rb:159:in `process_client'
/usr/lib/ruby/1.8/mongrel.rb:158:in `each'
/usr/lib/ruby/1.8/mongrel.rb:158:in `process_client'
/usr/lib/ruby/1.8/mongrel.rb:285:in `run'
/usr/lib/ruby/1.8/mongrel.rb:285:in `initialize'
/usr/lib/ruby/1.8/mongrel.rb:285:in `new'
/usr/lib/ruby/1.8/mongrel.rb:285:in `run'
/usr/lib/ruby/1.8/mongrel.rb:268:in `initialize'
/usr/lib/ruby/1.8/mongrel.rb:268:in `new'
/usr/lib/ruby/1.8/mongrel.rb:268:in `run'
/usr/lib/ruby/1.8/mongrel/configurator.rb:282:in `run'
/usr/lib/ruby/1.8/mongrel/configurator.rb:281:in `each'
/usr/lib/ruby/1.8/mongrel/configurator.rb:281:in `run'
/usr/bin/mongrel_rails:129:in `run'
/usr/lib/ruby/1.8/mongrel/command.rb:212:in `run'
/usr/bin/mongrel_rails:282
This is a conflict between Rails 3.1, Builder 3.0, and either the fast_xs gem or hpricot (which bundles fast_xs). The reason why some people can't reproduce it is that they don't have fast_xs or hpricot in their Gemfile.
Unfortunately, since it's a three-way conflict, everybody thinks it's the other library's fault:
Builder bug report
Rails pull request
fast_xs bug report
In the meantime, pile another monkey patch on the heap and add config/initializers/unbreak_string_to_xs.rb with the following:
class String
def fast_xs_absorb_args(*args); fast_xs; end
alias_method :to_xs, :fast_xs_absorb_args
end
(From this answer to a duplicate.)
Try (re)installing the 'builder' gem, that fixed the '1 for 0 arguments' bug for me :)
sudo gem install builder
Don't forget to restart your server afterwards
I would kind of like to blame the "for o in #orders" part. Perhaps trying with a traditional way would help to eliminate this suspicion:
#orders.each do |o|
...
end