stack level to deep Rails 2.3.14 - ruby-on-rails

I'm developing a plugin for a management framework and when I start the webrick server in the development mode, a strange error raises(stack level too deep). It happens when an action (e.g. the show action) starts to render a template. Unfortunately i have no idea why this is happen.
SystemStackError in Stories#show
Showing vendor/plugins/stories/app/views/stories/show.rhtml where line #5 raised:
stack level too deep
Extracted source (around line #5):
5: link_to_if_authorized 'aa', {:controller => "stories", :action => "index", :id => #story.id, :project_id => #story.project.id}, :title => l(:view_story), :class => 'icon icon-zoom-out'
6: link_to_if_authorized 'bb', {:controller => "stories", :action => "edit", :id => #story.id, :project_id => #story.project.id}, :title => l(:button_edit), :class => 'icon icon-edit'
7: link_to 'bb', {:id => #story.id, :project_id => #story.project.id}, :confirm => 'Really delete?', :method => :delete, :class => 'icon icon-del' if User.current.allowed_to? (:delete_stories, #project)
RAILS_ROOT: /home/haendwic/Documents/Aptana Studio 3 Workspace/1.4-stable-SVN
Application Trace | Framework Trace | Full Trace
/var/lib/gems/1.8/gems/activerecord-2.3.14/lib/active_record/attribute_methods.rb:248:in method_missing'
/var/lib/gems/1.8/gems/activerecord-2.3.14/lib/active_record/attribute_methods.rb:249:in method_missing'
/var/lib/gems/1.8/gems/activerecord-2.3.14/lib/active_record/associations /association_proxy.rb:215:in send'
/var/lib/gems/1.8/gems/activerecord-2.3.14/lib/active_record/associations/association_proxy.rb:215:in method_missing'
/home/haendwic/Documents/Aptana Studio 3 Workspace/1.4-stable-SVN/vendor/plugins/stories/app/views/stories/show.rhtml:5:in _run_rhtml_vendor47plugins47stories47app47views47stories47show46rhtml'
/var/lib/gems/1.8/gems/actionpack-2.3.14/lib/action_view/renderable.rb:34:in send'
/var/lib/gems/1.8/gems/actionpack-2.3.14/lib/action_view/renderable.rb:34:in render'
/var/lib/gems/1.8/gems/actionpack-2.3.14/lib/action_view/base.rb:306:in with_template'
/var/lib/gems/1.8/gems/actionpack-2.3.14/lib/action_view/renderable.rb:30:in render'
/var/lib/gems/1.8/gems/actionpack-2.3.14/lib/action_view/template.rb:205:in render_template'
/var/lib/gems/1.8/gems/actionpack-2.3.14/lib/action_view/base.rb:265:in render'
/var/lib/gems/1.8/gems/actionpack-2.3.14/lib/action_view/base.rb:348:in _render_with_layout'
/var/lib/gems/1.8/gems/actionpack-2.3.14/lib/action_view/base.rb:262:in render'
/var/lib/gems/1.8/gems/actionpack-2.3.14/lib/action_controller/base.rb:1252:in render_for_file'
/var/lib/gems/1.8/gems/actionpack-2.3.14/lib/action_controller/base.rb:936:in render_without_benchmark'
/var/lib/gems/1.8/gems/actionpack-2.3.14/lib/action_controller/benchmarking.rb:51:in render'
/var/lib/gems/1.8/gems/activesupport-2.3.14/lib/active_support/core_ext/benchmark.rb:17:in ms'
/usr/lib/ruby/1.8/benchmark.rb:308:in realtime'
/var/lib/gems/1.8/gems/activesupport-2.3.14/lib/active_support/core_ext/benchmark.rb:17:in ms'
/var/lib/gems/1.8/gems/actionpack-2.3.14/lib/action_controller/benchmarking.rb:51:in render'
/home/haendwic/Documents/Aptana Studio 3 Workspace/1.4-stable-SVN/vendor/plugins/stories/app/controllers/stories_controller.rb:104:in show'
/var/lib/gems/1.8/gems/actionpack-2.3.14/lib/action_controller/mime_responds.rb:135:in call'
/var/lib/gems/1.8/gems/actionpack-2.3.14/lib/action_controller/mime_responds.rb:135:in custom'
/var/lib/gems/1.8/gems/actionpack-2.3.14/lib/action_controller/mime_responds.rb:179:in call'
/var/lib/gems/1.8/gems/actionpack-2.3.14/lib/action_controller/mime_responds.rb:179:in respond'
/var/lib/gems/1.8/gems/actionpack-2.3.14/lib/action_controller/mime_responds.rb:173:in each'
/var/lib/gems/1.8/gems/actionpack-2.3.14/lib/action_controller/mime_responds.rb:173:in respond'
/var/lib/gems/1.8/gems/actionpack-2.3.14/lib/action_controller/mime_responds.rb:107:in respond_to'
/home/haendwic/Documents/Aptana Studio 3 Workspace/1.4-stable-SVN/vendor/plugins/stories/app/controllers/stories_controller.rb:102:in show'
/var/lib/gems/1.8/gems/actionpack-2.3.14/lib/action_controller/base.rb:1333:in send'
/var/lib/gems/1.8/gems/actionpack-2.3.14/lib/action_controller/base.rb:1333:in perform_action_without_filters'
/var/lib/gems/1.8/gems/actionpack-2.3.14/lib/action_controller/filters.rb:617:in call_filters'
/var/lib/gems/1.8/gems/actionpack-2.3.14/lib/action_controller/filters.rb:610:in perform_action_without_benchmark'
/var/lib/gems/1.8/gems/actionpack-2.3.14/lib/action_controller/benchmarking.rb:68:in perform_action_without_rescue'
/var/lib/gems/1.8/gems/activesupport-2.3.14/lib/active_support/core_ext/benchmark.rb:17:in ms'
/usr/lib/ruby/1.8/benchmark.rb:308:in realtime'
/var/lib/gems/1.8/gems/activesupport-2.3.14/lib/active_support/core_ext/benchmark.rb:17:in ms'
/var/lib/gems/1.8/gems/actionpack-2.3.14/lib/action_controller/benchmarking.rb:68:in perform_action_without_rescue'
/var/lib/gems/1.8/gems/actionpack-2.3.14/lib/action_controller/rescue.rb:160:in perform_action_without_flash'
/var/lib/gems/1.8/gems/actionpack-2.3.14/lib/action_controller/flash.rb:151:in perform_action'
/var/lib/gems/1.8/gems/actionpack-2.3.14/lib/action_controller/base.rb:532:in send'
/var/lib/gems/1.8/gems/actionpack-2.3.14/lib/action_controller/base.rb:532:in process_without_filters'
/var/lib/gems/1.8/gems/actionpack-2.3.14/lib/action_controller/filters.rb:606:in process'
/var/lib/gems/1.8/gems/actionpack-2.3.14/lib/action_controller/base.rb:391:in process'
/var/lib/gems/1.8/gems/actionpack-2.3.14/lib/action_controller/base.rb:386:in call'
/var/lib/gems/1.8/gems/actionpack-2.3.14/lib/action_controller/routing/route_set.rb:438:in call'
/var/lib/gems/1.8/gems/actionpack-2.3.14/lib/action_controller/dispatcher.rb:87:in dispatch'
/var/lib/gems/1.8/gems/actionpack-2.3.14/lib/action_controller/dispatcher.rb:121:in _call'
/var/lib/gems/1.8/gems/actionpack-2.3.14/lib/action_controller/dispatcher.rb:130:in build_middleware_stack'
/var/lib/gems/1.8/gems/activerecord-2.3.14/lib/active_record/query_cache.rb:29:in call'
/var/lib/gems/1.8/gems/activerecord-2.3.14/lib/active_record/query_cache.rb:29:in call'
/var/lib/gems/1.8/gems/activerecord-2.3.14/lib/active_record/connection_adapters/abstract/query_cache.rb:34:in cache'
/var/lib/gems/1.8/gems/activerecord-2.3.14/lib/active_record/query_cache.rb:9:in cache'
/var/lib/gems/1.8/gems/activerecord-2.3.14/lib/active_record/query_cache.rb:28:in call'
/var/lib/gems/1.8/gems/activerecord-2.3.14/lib/active_record/connection_adapters/abstract/connection_pool.rb:361:in call'
/var/lib/gems/1.8/gems/actionpack-2.3.14/lib/action_controller/string_coercion.rb:25:in call'
/var/lib/gems/1.8/gems/rack-1.1.3/lib/rack/head.rb:9:in call'
/var/lib/gems/1.8/gems/rack-1.1.3/lib/rack/methodoverride.rb:24:in call'
/var/lib/gems/1.8/gems/actionpack-2.3.14/lib/action_controller/params_parser.rb:15:in call'
/var/lib/gems/1.8/gems/actionpack-2.3.14/lib/action_controller/session /cookie_store.rb:99:in call'
/var/lib/gems/1.8/gems/actionpack-2.3.14/lib/action_controller/failsafe.rb:26:in call'
/var/lib/gems/1.8/gems/rack-1.1.3/lib/rack/lock.rb:11:in call'
/var/lib/gems/1.8/gems/rack-1.1.3/lib/rack/lock.rb:11:in synchronize'
/var/lib/gems/1.8/gems/rack-1.1.3/lib/rack/lock.rb:11:in call'
/var/lib/gems/1.8/gems/actionpack-2.3.14/lib/action_controller/dispatcher.rb:114:in call'
/var/lib/gems/1.8/gems/actionpack-2.3.14/lib/action_controller/reloader.rb:34:in run'
/var/lib/gems/1.8/gems/actionpack-2.3.14/lib/action_controller/dispatcher.rb:108:in call'
/var/lib/gems/1.8/gems/rails-2.3.14/lib/rails/rack/static.rb:31:in call'
/var/lib/gems/1.8/gems/rack-1.1.3/lib/rack/urlmap.rb:47:in call'
/var/lib/gems/1.8/gems/rack-1.1.3/lib/rack/urlmap.rb:41:in each'
/var/lib/gems/1.8/gems/rack-1.1.3/lib/rack/urlmap.rb:41:in call'
/var/lib/gems/1.8/gems/rails-2.3.14/lib/rails/rack/log_tailer.rb:17:in call'
/var/lib/gems/1.8/gems/rack-1.1.3/lib/rack/content_length.rb:13:in call'
/var/lib/gems/1.8/gems/rack-1.1.3/lib/rack/handler/webrick.rb:48:in service'
/usr/lib/ruby/1.8/webrick/httpserver.rb:104:in service'
/usr/lib/ruby/1.8/webrick/httpserver.rb:65:in run'
/usr/lib/ruby/1.8/webrick/server.rb:173:in start_thread'
/usr/lib/ruby/1.8/webrick/server.rb:162:in start'
/usr/lib/ruby/1.8/webrick/server.rb:162:in start_thread'
/usr/lib/ruby/1.8/webrick/server.rb:95:in start'
/usr/lib/ruby/1.8/webrick/server.rb:92:in each'
/usr/lib/ruby/1.8/webrick/server.rb:92:in start'
/usr/lib/ruby/1.8/webrick/server.rb:23:in start'
/usr/lib/ruby/1.8/webrick/server.rb:82:in start'
/var/lib/gems/1.8/gems/rack-1.1.3/lib/rack/handler/webrick.rb:14:in run'
/var/lib/gems/1.8/gems/rails-2.3.14/lib/commands/server.rb:111
script/server:3:in require'
script/server:3
Request
Parameters:
{"project_id"=>"1",
"id"=>"2"}
Show session dump
Response
Headers:
{"Cache-Control"=>"no-cache",
"Content-Type"=>"text/html"}
and here is the action from the controller
def show
#edit_allowed = User.current.allowed_to?(:edit_stories, #project)
respond_to do |format|
format.html {
render :template => 'stories/show'
}
format.api
format.pdf { send_data(story_to_pdf(#story), :type => 'application/pdf', :filename => "#{#project.identifier}-#{#story.id}.pdf") }
end
end
and at last a part of the view
link_to_if_authorized 'aa', {:controller => "stories", :action => "index", :id => #story.id, :project_id => #story.project.id}, :title => l(:view_story), :class => 'icon icon-zoom-out'
link_to_if_authorized 'bb', {:controller => "stories", :action => "edit", :id => #story.id, :project_id => #story.project.id}, :title => l(:button_edit), :class => 'icon icon-edit'
link_to 'bb', {:id => #story.id, :project_id => #story.project.id}, :confirm => 'Really delete?', :method => :delete, :class => 'icon icon-del' if User.current.allowed_to?(:delete_stories, #project)
Maybe it's important to say, that in the production mode the plugin is stable and routes the actions (incl. show) correctly

This is typically caused by you (or others) patching core models (probably the Project model) from a plugin without taking the rails reloader into account.
If you override methods (e.g. using alias_method_chain) and your patch is loaded twice, you can easily create an infinite loop when calling the old method.
# This is our initial class
class MyClass
def foo
puts "original foo"
end
end
module Patch
def self.included(base)
base.alias_method_chain :foo, :feature
end
def foo_with_feature
foo_without_feature # call the "original" method
puts "foo with feature"
end
end
# patch the class
MyClass.send(:include, Patch)
# Now call the patched method
MyClass.new.foo
# prints:
# original foo
# foo with feature
foo now refers to the method foo_with_feature while the original foo method now is accessible from foo_without_feature
All right, until now everything looked good. Now let's see what happens, if we load our patch again
# patch again
MyClass.send(:include, Patch)
# And call the method again
MyClass.new.foo
# SystemStackError: stack level too deep
# from (irb):7:in `foo_without_feature'
# from (irb):7:in `foo'
# from (irb):27
You see a SystemStackError caused by an infinite loop. This is because after the second loading of the patch, foo_without_feature now refers to the foo_with_feature method from the first patch. When calling it, it will over and over again call foo_without_feature until the stack is full.
You said that it only crashes on the second request. This is exactly the typical behavior when something is odd on the class reloader. By default, Rails will reload all classes on every request in development mode but only once in production mode.
Taming the rails reloader is a bit tricky sometimes. As some general guidelines, you should
use require_dependency instead of require when loading patches
load your patches using Dispatcher.to_prepare
always declare the patched classes unloadable
The most critical part is using Dispatcher.to_prepare. It is a callback which is called once in production mode and before each request in development mode and is thus the ideal place for loading patches.
As a side note though: When using Redmine 2 (or the upcoming ChiliProject 4), i.e. Rails 3, the class patching will be rather different from this approach - most probably easier.

The "stack level too deep" error means that you have a stack overflow (it happens often enough to have a site named after it). That occurs when a function calls itself indefinitely or when two functions call each other indefinitely.
Your error happens on line 5, so I'd check the source for link_to_if_authorized. Something in there is causing an infinite loop.

Related

Encoding::UndefinedConversionError: "\xA8" from ASCII-8BIT to UTF-8 (SFTP)

Using the Net-SFTP gem, Ruby 2 and Rails 4
I wrote code that was working in pure ruby, but copied my code over to rails and now I get:
Encoding::UndefinedConversionError: "\xA8" from ASCII-8BIT to UTF-8
What can I change in my code to get this working?
def self.get_recent_file(ftp_file, local_file)
Net::SFTP.start(Config::A_FTP[:domain], Config::A_FTP[:username], :password => Config::A_FTP[:password]) do |sftp|
sftp.download!(ftp_file, local_file)
end
end
Log
Encoding::UndefinedConversionError: "\xA8" from ASCII-8BIT to UTF-8
from /usr/local/opt/rbenv/versions/2.1.0-rc1/lib/ruby/gems/2.1.0/gems/net-sftp-2.1.2/lib/net/sftp/operations/download.rb:339:in `write'
from /usr/local/opt/rbenv/versions/2.1.0-rc1/lib/ruby/gems/2.1.0/gems/net-sftp-2.1.2/lib/net/sftp/operations/download.rb:339:in `write'
from /usr/local/opt/rbenv/versions/2.1.0-rc1/lib/ruby/gems/2.1.0/gems/net-sftp-2.1.2/lib/net/sftp/operations/download.rb:339:in `on_read'
from /usr/local/opt/rbenv/versions/2.1.0-rc1/lib/ruby/gems/2.1.0/gems/net-sftp-2.1.2/lib/net/sftp/request.rb:87:in `call'
from /usr/local/opt/rbenv/versions/2.1.0-rc1/lib/ruby/gems/2.1.0/gems/net-sftp-2.1.2/lib/net/sftp/request.rb:87:in `respond_to'
from /usr/local/opt/rbenv/versions/2.1.0-rc1/lib/ruby/gems/2.1.0/gems/net-sftp-2.1.2/lib/net/sftp/session.rb:948:in `dispatch_request'
from /usr/local/opt/rbenv/versions/2.1.0-rc1/lib/ruby/gems/2.1.0/gems/net-sftp-2.1.2/lib/net/sftp/session.rb:911:in `when_channel_polled'
from /usr/local/opt/rbenv/versions/2.1.0-rc1/lib/ruby/gems/2.1.0/gems/net-ssh-2.8.0/lib/net/ssh/connection/channel.rb:311:in `call'
from /usr/local/opt/rbenv/versions/2.1.0-rc1/lib/ruby/gems/2.1.0/gems/net-ssh-2.8.0/lib/net/ssh/connection/channel.rb:311:in `process'
from /usr/local/opt/rbenv/versions/2.1.0-rc1/lib/ruby/gems/2.1.0/gems/net-ssh-2.8.0/lib/net/ssh/connection/session.rb:222:in `block in preprocess'
from /usr/local/opt/rbenv/versions/2.1.0-rc1/lib/ruby/gems/2.1.0/gems/net-ssh-2.8.0/lib/net/ssh/connection/session.rb:222:in `each'
from /usr/local/opt/rbenv/versions/2.1.0-rc1/lib/ruby/gems/2.1.0/gems/net-ssh-2.8.0/lib/net/ssh/connection/session.rb:222:in `preprocess'
from /usr/local/opt/rbenv/versions/2.1.0-rc1/lib/ruby/gems/2.1.0/gems/net-ssh-2.8.0/lib/net/ssh/connection/session.rb:205:in `process'
from /usr/local/opt/rbenv/versions/2.1.0-rc1/lib/ruby/gems/2.1.0/gems/net-ssh-2.8.0/lib/net/ssh/connection/session.rb:169:in `block in loop'
from /usr/local/opt/rbenv/versions/2.1.0-rc1/lib/ruby/gems/2.1.0/gems/net-ssh-2.8.0/lib/net/ssh/connection/session.rb:169:in `loop'
from /usr/local/opt/rbenv/versions/2.1.0-rc1/lib/ruby/gems/2.1.0/gems/net-ssh-2.8.0/lib/net/ssh/connection/session.rb:169:in `loop'
... 13 levels...
from /usr/local/opt/rbenv/versions/2.1.0-rc1/lib/ruby/gems/2.1.0/gems/net-ssh-2.8.0/lib/net/ssh/connection/session.rb:222:in `preprocess'
from /usr/local/opt/rbenv/versions/2.1.0-rc1/lib/ruby/gems/2.1.0/gems/net-ssh-2.8.0/lib/net/ssh/connection/session.rb:205:in `process'
from /usr/local/opt/rbenv/versions/2.1.0-rc1/lib/ruby/gems/2.1.0/gems/net-ssh-2.8.0/lib/net/ssh/connection/session.rb:169:in `block in loop'
from /usr/local/opt/rbenv/versions/2.1.0-rc1/lib/ruby/gems/2.1.0/gems/net-ssh-2.8.0/lib/net/ssh/connection/session.rb:169:in `loop'
from /usr/local/opt/rbenv/versions/2.1.0-rc1/lib/ruby/gems/2.1.0/gems/net-ssh-2.8.0/lib/net/ssh/connection/session.rb:169:in `loop'
from /usr/local/opt/rbenv/versions/2.1.0-rc1/lib/ruby/gems/2.1.0/gems/net-sftp-2.1.2/lib/net/sftp/session.rb:802:in `loop'
from /usr/local/opt/rbenv/versions/2.1.0-rc1/lib/ruby/gems/2.1.0/gems/net-sftp-2.1.2/lib/net/sftp/session.rb:787:in `connect!'
from /usr/local/opt/rbenv/versions/2.1.0-rc1/lib/ruby/gems/2.1.0/gems/net-sftp-2.1.2/lib/net/sftp.rb:32:in `start'
Code referenced in log from GEM:
https://github.com/net-ssh/net-sftp/blob/master/lib/net/sftp/operations/download.rb#L339
# Called when a read from a file finishes. If the read was successful
# and returned data, this will call #download_next_chunk to read the
# next bit from the file. Otherwise the file will be closed.
def on_read(response)
entry = response.request[:entry]
if response.eof?
update_progress(:close, entry)
entry.sink.close
request = sftp.close(entry.handle, &method(:on_close))
request[:entry] = entry
elsif !response.ok?
raise "read #{entry.remote}: #{response}"
else
entry.offset += response[:data].bytesize
update_progress(:get, entry, response.request[:offset], response[:data])
entry.sink.write(response[:data]) # <~~ Line#339
download_next_chunk(entry)
end
end
This helps me:
def self.get_recent_file(ftp_file, local_file)
local_io = File.new(local_file, mode: 'w', encoding: 'ASCII-8BIT')
Net::SFTP.start(Config::A_FTP[:domain], Config::A_FTP[:username], :password => Config::A_FTP[:password]) do |sftp|
sftp.download!(ftp_file, local_io)
end
local_io.close
end
A combination of user72136's answer and the answer to this question worked for me (my remote file wasn't even ASCII):
def self.get_recent_file(ftp_file, local_file)
local_io = File.new(local_file, mode: 'wb')
Net::SFTP.start(Config::A_FTP[:domain], Config::A_FTP[:username], :password => Config::A_FTP[:password]) do |sftp|
sftp.download!(ftp_file, local_io)
end
local_io.close
end
As line#339 is showing
entry.sink.write(response[:data])
Fix it as :
entry.sink.write(response[:data].force_encoding('ASCII-8BIT').encode('UTF-8'))
Change the line -
sftp.download!(ftp_file, local_file)
to say
sftp.download!(ftp_file, local_file).to_s.encode('UTF-8', {:invalid => :replace, :undef => :replace, :replace => '?'})
This problem is being produced by how Ruby opens text-files by default after Ruby 2.0 version with UTF-8 encoding. Where you open your file you can put:
local_file = Tempfile.new(encoding: 'ascii-8bit')
#or another thing to do is to switch to binary-mode
local_file = Tempfile.new
local_file.binmode
You can also open a binary-file like this:
local_file = File.open('/tmp/local_file', 'wb')
Another solution you can do is to pass to the gem-code the filepath, instead of an open file:
def self.get_recent_file(ftp_file, local_file)
Net::SFTP.start(Config::A_FTP[:domain], Config::A_FTP[:username], :password => Config::A_FTP[:password]) do |sftp|
sftp.download!(ftp_file, local_file.path)
end
end

Using Rails ActionView/Controller completely outside rails

I learnt a bit of basic Rails and one of the attempts I'm making now is to use ActionController and ActionView completely outside of Rails (in a non rails app).
So far what I have is the following example after installing actionpack-4.0.2
require 'action_view'
require 'action_controller'
class SimpleController < AbstractController::Base
include AbstractController::Rendering
include AbstractController::Layouts
include AbstractController::Helpers
include AbstractController::Translation
include AbstractController::AssetPaths
include ActionController::UrlFor
include ActionDispatch::Routing::UrlFor
# All the .html.erb files are placed in the folder Views
self.view_paths = "Views"
def say_hello
render_to_string template: "Hello"
end
def create_person
render_to_string template: "Form"
end
end
c = SimpleController.new
puts c.say_hello
puts c.create_person
Hello.html.erb (To be placed in the Views folder)
<html>
<body>
<p>
<%= highlight( 'This is Hello world', 'Hello world') %>
</p>
</body>
</html>
Form.html.erb (To be placed in the Views folder)
<html>
<body>
<%= form_for( :person, :url => { :action => 'create' } ) do |f| %>
<%= f.text_field :first_name %>
<%= f.text_field :last_name %>
<%= f.password_field :password %>
<%= submit_tag 'Create' %>
<% end %>
</body>
</html>
Below is the output of the above program
<html>
<body>
<p>
This is <mark>Hello world</mark>
</p>
</body>
</html>
C:/Ruby193/lib/ruby/gems/1.9.1/gems/actionpack-4.0.2/lib/action_view/helpers/url
_helper.rb:38:in `url_for': arguments passed to url_for can't be handled. Please
require routes or provide your own implementation (ActionView::Template::Error)
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/actionpack-4.0.2/lib/action_vie
w/helpers/form_tag_helper.rb:729:in `block in html_options_for_form'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/actionpack-4.0.2/lib/action_vie
w/helpers/form_tag_helper.rb:725:in `tap'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/actionpack-4.0.2/lib/action_vie
w/helpers/form_tag_helper.rb:725:in `html_options_for_form'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/actionpack-4.0.2/lib/action_vie
w/helpers/form_tag_helper.rb:67:in `form_tag'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/actionpack-4.0.2/lib/action_vie
w/helpers/form_helper.rb:438:in `form_for'
from ./Views/Form.html.erb:4:in `_____etho
ds__uby_html___rototype__iews__orm_html_erb__678800263_20873052'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/actionpack-4.0.2/lib/action_vie
w/template.rb:143:in `block in render'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-4.0.2/lib/active_
support/notifications.rb:161:in `instrument'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/actionpack-4.0.2/lib/action_vie
w/template.rb:141:in `render'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/actionpack-4.0.2/lib/action_vie
w/renderer/template_renderer.rb:49:in `block (2 levels) in render_template'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/actionpack-4.0.2/lib/action_vie
w/renderer/abstract_renderer.rb:38:in `block in instrument'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-4.0.2/lib/active_
support/notifications.rb:159:in `block in instrument'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-4.0.2/lib/active_
support/notifications/instrumenter.rb:20:in `instrument'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-4.0.2/lib/active_
support/notifications.rb:159:in `instrument'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/actionpack-4.0.2/lib/action_vie
w/renderer/abstract_renderer.rb:38:in `instrument'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/actionpack-4.0.2/lib/action_vie
w/renderer/template_renderer.rb:48:in `block in render_template'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/actionpack-4.0.2/lib/action_vie
w/renderer/template_renderer.rb:56:in `render_with_layout'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/actionpack-4.0.2/lib/action_vie
w/renderer/template_renderer.rb:47:in `render_template'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/actionpack-4.0.2/lib/action_vie
w/renderer/template_renderer.rb:17:in `render'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/actionpack-4.0.2/lib/action_vie
w/renderer/renderer.rb:42:in `render_template'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/actionpack-4.0.2/lib/action_vie
w/renderer/renderer.rb:23:in `render'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/actionpack-4.0.2/lib/abstract_c
ontroller/rendering.rb:127:in `_render_template'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/actionpack-4.0.2/lib/abstract_c
ontroller/rendering.rb:120:in `render_to_body'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/actionpack-4.0.2/lib/abstract_c
ontroller/rendering.rb:113:in `render_to_string'
from sample.rb:21:in `edit_person'
from sample.rb:28:in `<main>'
The say_hello method works fine with out any issues and I can use most of the ActiveView ViewHelpers in the erb files (Hello.html.erb above uses one such highlight method). So this is a way with which I can generate static html pages by using power of ActionView.
But I'm not able to get the edit_person work as it uses form_for helper and this needs custom url_for implementation or rails standard routes.rb implementation (as prompted in the error message). I would like to get this working with routes.rb approach but I get the impression that I need Rails::Application object and some url_helpers etc (so far I couldn't get it working). Is there a way to do this?
Then later I would like integrate this solution with Webrick to process the requests from browser (when the user creates a person).
Please note this is a attempt to learn some details of Rails and not meant as a solution to any problem that you cannot do with using standard rails framework. Any help would be greatly appreciated.
Not an answer but just for some related code.
To simplify things a bit and I know it still errors but you get some data back in the errors.
I'll show a portion of it after the code.
require 'action_controller'
class SimpleController < ActionController::Base
def say_hello
p render_to_string template: "Hello"
end
def create_person
p render_to_string template: "Form"
end
end
c = SimpleController.new
puts c.say_hello
puts c.create_person
Skipping the views handler for now.
OUT:
> ruby sample.rb
/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/actionview- 4.1.8/lib/action_view/path_set.rb:46:in `find': Missing template /Hello with {:locale=>[:en], :formats=>[:html, :text, :js, :css, :ics, :csv, :vcf, :png, :jpeg, :gif, :bmp, :tiff, :mpeg, :xml, :rss, :atom, :yaml, :multipart_form, :url_encoded_form, :json, :pdf, :zip], :variants=>[], :handlers=>[:erb, :builder, :raw, :ruby]}. Searched in: (ActionView::MissingTemplate)
The top should be good enough as it just trees up to that anyway.
Now a run with the class views.
We get similar results:
OUT:
ruby sample.rb
"\n \n \n This is Hello world\n \n \n"
<html>
<body>
<p>
This is <mark>Hello world</mark>
</p>
</body>
</html>
.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/actionview-4.1.8/lib/action_view/helpers/url_helper.rb:38:in `url_for': arguments passed to url_for can't be handled. Please require routes or provide your own implementation (ActionView::Template::Error)
Rails 5 introduced the ActionController::Renderer that makes it a bit more convenient to use the Rails template system outside of Rails.
Example:
renderer = ApplicationController.renderer
content = renderer.render template: 'ruby_template'
(from the Tests)
It's somewhat useful because plain ERB is severely limited. I'm using it in a generator where life without partials would be inconvenient.

Upgraded to Rails 2.3.11 and am getting an Uninitialized Constant::AWS error

I am trying to use our app to generate screenshots. However, instead I generate the following:
NameError in Step_results#show
Showing app/views/step_results/show.html.haml where line #26 raised:
uninitialized constant StepResult::AWS
Extracted source (around line #26):
23: %p{ :title => #step_result.message }= h #step_result.message
24: = link_to 'close window', '#', :onclick => 'window.close();'
25: = link_to 'Screenshot', html_screen_shot_src(#step_result), :class => 'screenshot', :target => "frame", :id => "screenshot", :onclick => '$("a#screenshot").hide(); $("a#screenscrape").show()' unless html_screen_shot_src(#step_result).nil?
26: = link_to 'Screen Scrape', html_screen_scrape_src(#step_result), :class => 'screenscrape', :target => "frame", :id => "screenscrape", :onclick => '$("a#screenscrape").hide(); $("a#screenshot").show()'
27:
28: #frame
29: %iframe{ :src => html_screen_scrape_src(#step_result), :name => 'frame' }
/Users/jasonbodak/.rvm/gems/ree-1.8.7-2011.03#janova-local_app/gems/activesupport-2.3.11/lib/active_support/dependencies.rb:131:in `const_missing'
/Users/jasonbodak/janova/janova/app/models/step_result.rb:73:in `html_scrape_url'
/Users/jasonbodak/janova/janova/app/helpers/step_results_helper.rb:3:in `html_screen_scrape_src'
/Users/jasonbodak/janova/janova/app/views/step_results/show.html.haml:26:in `_run_haml_app47views47step_results47show46html46haml'
/Users/jasonbodak/.rvm/gems/ree-1.8.7-2011.03#janova-local_app/gems/actionpack-2.3.11/lib/action_view/renderable.rb:34:in `send'
/Users/jasonbodak/.rvm/gems/ree-1.8.7-2011.03#janova-local_app/gems/actionpack-2.3.11/lib/action_view/renderable.rb:34:in `render'
/Users/jasonbodak/.rvm/gems/ree-1.8.7-2011.03#janova-local_app/gems/actionpack-2.3.11/lib/action_view/base.rb:306:in `with_template'
/Users/jasonbodak/.rvm/gems/ree-1.8.7-2011.03#janova-local_app/gems/actionpack-2.3.11/lib/action_view/renderable.rb:30:in `render'
/Users/jasonbodak/.rvm/gems/ree-1.8.7-2011.03#janova-local_app/gems/actionpack-2.3.11/lib/action_view/template.rb:205:in `render_template'
/Users/jasonbodak/.rvm/gems/ree-1.8.7-2011.03#janova-local_app/gems/actionpack-2.3.11/lib/action_view/base.rb:265:in `render_without_haml'
/Users/jasonbodak/.rvm/gems/ree-1.8.7-2011.03#janova-local_app/gems/haml-3.0.22/lib/haml/helpers/action_view_mods.rb:13:in `render'
/Users/jasonbodak/.rvm/gems/ree-1.8.7-2011.03#janova-local_app/gems/actionpack-2.3.11/lib/action_controller/base.rb:1252:in `render_for_file'
/Users/jasonbodak/.rvm/gems/ree-1.8.7-2011.03#janova-local_app/gems/actionpack-2.3.11/lib/action_controller/base.rb:978:in `render_without_benchmark'
/Users/jasonbodak/.rvm/gems/ree-1.8.7-2011.03#janova-local_app/gems/actionpack-2.3.11/lib/action_controller/benchmarking.rb:51:in `render'
/Users/jasonbodak/.rvm/gems/ree-1.8.7-2011.03#janova-local_app/gems/activesupport-2.3.11/lib/active_support/core_ext/benchmark.rb:17:in `ms'
/Users/jasonbodak/.rvm/gems/ree-1.8.7-2011.03#janova-local_app/gems/activesupport-2.3.11/lib/active_support/core_ext/benchmark.rb:17:in `ms'
/Users/jasonbodak/.rvm/gems/ree-1.8.7-2011.03#janova-local_app/gems/actionpack-2.3.11/lib/action_controller/benchmarking.rb:51:in `render'
/Users/jasonbodak/janova/janova/app/controllers/step_results_controller.rb:4:in `show'
/Users/jasonbodak/.rvm/gems/ree-1.8.7-2011.03#janova-local_app/gems/actionpack-2.3.11/lib/action_controller/base.rb:1333:in `send'
/Users/jasonbodak/.rvm/gems/ree-1.8.7-2011.03#janova-local_app/gems/actionpack-2.3.11/lib/action_controller/base.rb:1333:in `perform_action_without_filters'
/Users/jasonbodak/.rvm/gems/ree-1.8.7-2011.03#janova-local_app/gems/actionpack-2.3.11/lib/action_controller/filters.rb:617:in `call_filters'
/Users/jasonbodak/.rvm/gems/ree-1.8.7-2011.03#janova-local_app/gems/actionpack-2.3.11/lib/action_controller/filters.rb:610:in `perform_action_without_benchmark'
/Users/jasonbodak/.rvm/gems/ree-1.8.7-2011.03#janova-local_app/gems/actionpack-2.3.11/lib/action_controller/benchmarking.rb:68:in `perform_action_without_rescue'
/Users/jasonbodak/.rvm/gems/ree-1.8.7-2011.03#janova-local_app/gems/activesupport-2.3.11/lib/active_support/core_ext/benchmark.rb:17:in `ms'
/Users/jasonbodak/.rvm/gems/ree-1.8.7-2011.03#janova-local_app/gems/activesupport-2.3.11/lib/active_support/core_ext/benchmark.rb:17:in `ms'
/Users/jasonbodak/.rvm/gems/ree-1.8.7-2011.03#janova-local_app/gems/actionpack-2.3.11/lib/action_controller/benchmarking.rb:68:in `perform_action_without_rescue'
/Users/jasonbodak/.rvm/gems/ree-1.8.7-2011.03#janova-local_app/gems/actionpack-2.3.11/lib/action_controller/rescue.rb:160:in `perform_action_without_flash'
/Users/jasonbodak/.rvm/gems/ree-1.8.7-2011.03#janova-local_app/gems/actionpack-2.3.11/lib/action_controller/flash.rb:151:in `perform_action'
/Users/jasonbodak/.rvm/gems/ree-1.8.7-2011.03#janova-local_app/gems/actionpack-2.3.11/lib/action_controller/base.rb:532:in `send'
/Users/jasonbodak/.rvm/gems/ree-1.8.7-2011.03#janova-local_app/gems/actionpack-2.3.11/lib/action_controller/base.rb:532:in `process_without_filters'
/Users/jasonbodak/.rvm/gems/ree-1.8.7-2011.03#janova-local_app/gems/actionpack-2.3.11/lib/action_controller/filters.rb:606:in `process'
/Users/jasonbodak/.rvm/gems/ree-1.8.7-2011.03#janova-local_app/gems/actionpack-2.3.11/lib/action_controller/base.rb:391:in `process'
/Users/jasonbodak/.rvm/gems/ree-1.8.7-2011.03#janova-local_app/gems/actionpack-2.3.11/lib/action_controller/base.rb:386:in `call'
/Users/jasonbodak/.rvm/gems/ree-1.8.7-2011.03#janova-local_app/gems/actionpack-2.3.11/lib/action_controller/routing/route_set.rb:438:in `call'
Any ideas why I am suddenly getting an Amazon Worker Service error now? Thanks.
Edit: Here is the code for the html_scrape_url method:
def html_scrape_url
tries = 0
begin
return nil if html_filename.blank?
AWS::S3::S3Object.url_for(html_filename, s3_bucket)
rescue AWS::S3::NoConnectionEstablished => e
if tries < 1
logger.debug "S3 connection not established. Establishing..."
AWS::S3::Base.establish_connection!(
:access_key_id => APP_CONFIG[:amazon_access_key_id],
:secret_access_key => APP_CONFIG[:amazon_secret_access_key]
)
tries += 1
retry
end
end
end
OK, this is very weird, but adding
require 'aws/s3'
to the top of my model (called step_result.rb, as you can see above) fixed the issue. I must admit that I do not understand how doing that fixed it... I just tried it on a whim, but I'm glad I did.

Rails error with validation and multiple models, can't convert HashWithIndifferentAccess into String

I haven't used rails since version 1.2 or so and a few things have changed. I have an issue where I am trying to save an empty model to get validation errors on attributes using :validates_presence_of and instead I am getting the error 'can't convert HashWithIndifferentAccess into String'. I will attempt to simplify my code to get the point across as tersely as possible...
my model:
class Project < ActiveRecord::Base
validates_presence_of :title, :description
validates_uniqueness_of :title
has_one :address
accepts_nested_attributes_for :address, :allow_destroy => true
end
Child model:
class Address < ActiveRecord::Base
validates_presence_of :title, :street
belongs_to :project
end
controller:
class ProjectsController < ApplicationController
def create
#project = Project.new(params[:project])
if #project.save
flash[:notice] = #project.title + ' successfully created'
redirect_to projects_path
else
render :action => 'new'
end
end
end
view:
<%= error_messages_for 'project' %>
<% form_for #project do |f| %>
<table width="100%" cellpadding="3" cellspacing="0">
<tr>
<td class="adminlabel">
<label for="Title">Title</label>
</td>
<td class="adminbody">
<%= f.text_field :title %>
</td>
</tr>
.....
<% f.fields_for :address do |address| %>
....
This code adds and updates just fine as long as I fill in all the required fields, if I leave any blank I get the error mentioned above, not the most graceful way of alerting users there is an issue ;)
Request params:
{"commit"=>"Save",
"project"=>{"title"=>"",
"notes"=>"",
"description"=>"",
"address_attributes"=>{"city"=>"",
"zip"=>"",
"title"=>"",
"country"=>"",
"suite"=>"",
"street"=>"",
"state"=>""}},
"authenticity_token"=>"iNPQZrf/oBv22vaI0toTGhknwx0aAU3BSvnIh6qgYQ8="}
I have been searching for days and am at my wits end, if anyone can shed a little light on this for me I would greatly appreciate it.
Thanks in advance!
Brendan
PS - the stack trace as requested:
.../app/controllers/projects_controller.rb:27:in `+'
.../app/controllers/projects_controller.rb:27:in `create'
../actionpack-2.3.4/lib/action_controller/base.rb:1331:in `send'
../actionpack-2.3.4/lib/action_controller/base.rb:1331:in `perform_action_without_filters'
../actionpack-2.3.4/lib/action_controller/filters.rb:617:in `call_filters'
../actionpack-2.3.4/lib/action_controller/filters.rb:610:in `perform_action_without_benchmark'
../actionpack-2.3.4/lib/action_controller/benchmarking.rb:68:in `perform_action_without_rescue'
../activesupport-2.3.4/lib/active_support/core_ext/benchmark.rb:17:in `ms'
../activesupport-2.3.4/lib/active_support/core_ext/benchmark.rb:10:in `realtime'
../activesupport-2.3.4/lib/active_support/core_ext/benchmark.rb:17:in `ms'
../actionpack-2.3.4/lib/action_controller/benchmarking.rb:68:in `perform_action_without_rescue'
../actionpack-2.3.4/lib/action_controller/rescue.rb:160:in `perform_action_without_flash'
../actionpack-2.3.4/lib/action_controller/flash.rb:146:in `perform_action'
../actionpack-2.3.4/lib/action_controller/base.rb:532:in `send'
../actionpack-2.3.4/lib/action_controller/base.rb:532:in `process_without_filters'
../actionpack-2.3.4/lib/action_controller/filters.rb:606:in `process'
../actionpack-2.3.4/lib/action_controller/base.rb:391:in `process'
../actionpack-2.3.4/lib/action_controller/base.rb:386:in `call'
../actionpack-2.3.4/lib/action_controller/routing/route_set.rb:437:in `call'
../actionpack-2.3.4/lib/action_controller/dispatcher.rb:87:in `dispatch'
../actionpack-2.3.4/lib/action_controller/dispatcher.rb:121:in `_call'
../actionpack-2.3.4/lib/action_controller/dispatcher.rb:130:in `build_middleware_stack'
../activerecord-2.3.4/lib/active_record/query_cache.rb:29:in `call'
../activerecord-2.3.4/lib/active_record/query_cache.rb:29:in `call'
../activerecord-2.3.4/lib/active_record/connection_adapters/abstract/query_cache.rb:34:in `cache'
..activerecord-2.3.4/lib/active_record/query_cache.rb:9:in `cache'
../activerecord-2.3.4/lib/active_record/query_cache.rb:28:in `call'
../activerecord-2.3.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:361:in `call'
../rack-1.0.1/lib/rack/head.rb:9:in `call'
../rack-1.0.1/lib/rack/methodoverride.rb:24:in `call'
../actionpack-2.3.4/lib/action_controller/params_parser.rb:15:in `call'
../actionpack-2.3.4/lib/action_controller/session/cookie_store.rb:93:in `call'
../actionpack-2.3.4/lib/action_controller/failsafe.rb:26:in `call'
../rack-1.0.1/lib/rack/lock.rb:11:in `call'
../rack-1.0.1/lib/rack/lock.rb:11:in `synchronize'
../rack-1.0.1/lib/rack/lock.rb:11:in `call'
../actionpack-2.3.4/lib/action_controller/dispatcher.rb:114:in `call'
../actionpack-2.3.4/lib/action_controller/reloader.rb:34:in `run'
../actionpack-2.3.4/lib/action_controller/dispatcher.rb:108:in `call'
../rails-2.3.4/lib/rails/rack/static.rb:31:in `call'
../rack-1.0.1/lib/rack/urlmap.rb:46:in `call'
../rack-1.0.1/lib/rack/urlmap.rb:40:in `each'
../rack-1.0.1/lib/rack/urlmap.rb:40:in `call'
../rails-2.3.4/lib/rails/rack/log_tailer.rb:17:in `call'
../rack-1.0.1/lib/rack/content_length.rb:13:in `call'
../rack-1.0.1/lib/rack/chunked.rb:15:in `call'
../rack-1.0.1/lib/rack/handler/mongrel.rb:64:in `process'
..... etc.
A bit lengthy, sorry ;)
Try adding
#project.address.build
to your controller. You need to instantiate the address object.
The trace doesn't lie. You're having issues with a line 27. The code you posted doesn't have 37 lines, but based on the trace I'm willing to bet it's this line. Because none others have have a '+'. If there was an implicit + its caller would've been listed in the trace.
flash[:notice] = #project.title + ' successfully created'
It's odd that it's reaching that point based on your validations. validates_presence_of should add errors on attributes that are either nil, false or "". Does the validation fail as expected when run in the console?
Here's a console friendly version of your code that could be used to track down your issue. You should be able to just paste it into the console to help track down your issue.
params = {
"project"=> {
"title"=>"", "notes"=>"","description"=>"",
"address_attributes"=>{
"city"=>"", "zip"=>"","title"=>"","country"=>"",
"suite"=>"","street"=>"","state"=>""
}
}
flash = {}
#project = Project.new(params[:project])
if #project.save
flash[:notice] = #project.title + ' successfully created'
puts "Saved. Flash: #{flash[:notice]}"
else
puts "validations failed:"
puts #project.errors.full_messages.map{|m| "\t#{m}"}.join("\n")
end

Diagnosing Rails Application Hang on Element Update

In the course of building a rails application to help small hotels' manage bookings, I'm encountering a strange application hang. Building the reservation works fine; adding guests, assigning them to rooms, etc, without issue. However, when the merchant goes to 'confirm' an inquiry, Mongrel hangs me out to dry.
The index page for reservations lists the current inquiries and confirmed bookings:
# reservations/index.html.erb
<% unless #reservations.empty? %>
<h2>Inquiries</h2><hr/><br/>
<%= render :partial => 'reservation', :collection => #reservations.reject { |r| r.confirmed } %>
<h2>Confirmed Reservations</h2><hr/><br/>
<%= render :partial => 'reservation', :collection => #reservations.reject { |r| not r.confirmed } %>
<% else %>
<%= link_to 'Search for rooms', :action => 'index', :controller => 'search' %>
<% end %>
In the reservation partial itself, the bits which invoke the confirm/unconfirm logic are simply direct links to controller actions:
# _reservation.html.erb
(<% unless reservation.confirmed? %>
<%= link_to 'Confirm Reservation', :action => 'confirm', :id => reservation.id %>
<% else %>
<%= link_to 'Unconfirm Reservation', :action => 'unconfirm', :id => reservation.id %>
<% end %>)
The controller action to confirm a reservation, which is mapped to a PUT in my routes, looks like this:
def confirm
puts "\n\n\nConfirming reservation #{params[:id]}..."
#reservation = Reservation.find(params[:id])
puts "Found reservation! Confirming..."
#reservation[:confirmed] = true
puts "Confirmed, saving..."
respond_to do |wants|
if #reservation.save
flash[:notice] = 'Reservation has been confirmed.'
wants.html { redirect_to :action => 'index' }
else
wants.html { render :action => 'index' }
end
end
end
'#reservation.save' is what does the trick. Definite app hang every time.
Can someone help me understand just what is going on here?
/UPDATE:
From playing around with the console I was able to demonstrate the issue in another way:
?> r = Reservation.find(36)
=> #<Reservation id: 36, customer_name: "buyer", customer_email: "buyer#buy.com", begin: "2009-06-22 00:00:00", end: "2009-06-26 00:00:00", request_timestamp: nil, notes: "Thanks!", created_at: "2009-06-13 20:36:50", updated_at: "2009-06-13 20:36:50", yacht_id: 7, adults: 1, children: 0, buyer_id: 3, confirmed: nil>
>> r.confirmed = true
=> true
>> r
=> #<Reservation id: 36, customer_name: "buyer", customer_email: "buyer#buy.com", begin: "2009-06-22 00:00:00", end: "2009-06-26 00:00:00", request_timestamp: nil, notes: "Thanks!", created_at: "2009-06-13 20:36:50", updated_at: "2009-06-13 20:36:50", yacht_id: 7, adults: 1, children: 0, buyer_id: 3, confirmed: true>
>> r.save!
IRB::Abort: abort then interrupt!!
from C:/Ruby/lib/ruby/1.8/irb.rb:81:in `irb_abort'
from C:/Ruby/lib/ruby/1.8/irb.rb:247:in `signal_handle'
from C:/Ruby/lib/ruby/1.8/irb.rb:66:in `start'
from C:/Ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.2/lib/active_support/callbacks.rb:275:in `call'
from C:/Ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.2/lib/active_support/callbacks.rb:275:in `run_callbacks'
from C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/callbacks.rb:344:in `callback'
from C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/callbacks.rb:318:in `valid?'
from C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/associations/association_proxy.rb:221:in `send'
from C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/associations/association_proxy.rb:221:in `method_missing'
from C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/validations.rb:906:in `validates_associated'
from C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/validations.rb:906:in `collect'
from C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/validations.rb:906:in `validates_associated'
from C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/validations.rb:399:in `validates_each'
from C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/validations.rb:396:in `each'
from C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/validations.rb:396:in `validates_each'
from C:/Ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.2/lib/active_support/callbacks.rb:182:in `call'
... 2204 levels...
from C:/Ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.2/lib/active_support/callbacks.rb:90:in `run'
from C:/Ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.2/lib/active_support/callbacks.rb:90:in `each'
from C:/Ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.2/lib/active_support/callbacks.rb:90:in `send'
from C:/Ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.2/lib/active_support/callbacks.rb:90:in `run'
from C:/Ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.2/lib/active_support/callbacks.rb:276:in `run_callbacks'
from C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/validations.rb:1029:in `valid_without_callbacks?'
from C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/callbacks.rb:315:in `valid?'
from C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/validations.rb:1018:in `save_without_dirty!'
from C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/dirty.rb:87:in `save_without_transactions!'
from C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/transactions.rb:200:in `save!'
from C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/abstract/database_statements.rb:136:in `transaction'
from C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/transactions.rb:182:in `transaction'
from C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/transactions.rb:200:in `save!'
from C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/transactions.rb:208:in `rollback_active_record_state!'
from C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/transactions.rb:200:in `save!'
from (irb):5>>
Note that the console locked up as well, and I had to abort the save! command using Ctrl-C.
Why in the world would the save! be doing this?
/UPDATE:
Got it!!! It was in my model. I was trying to validate an association and I had gotten the has_many/belongs_to stuff backwards.
Thanks, everyone!
Your issue may be this:
#reservation[:confirmed] = true
You're directly updating the attributes hash, which is a little odd. Normally, you'd just update the attribute.
#reservation.confirmed = true
I've had odd issues before when I messed with the attribute hash. Booleans especially - maybe because there is some type coercion happening.
Use thin instead of mongrel. Post more details from your log. It doesn't just hang like that usually.

Resources