Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #7418 (closed defect: fixed)

Opened 1 year ago

Last modified 7 months ago

[PATCH] in_place_edit_for fails when used with a non-string-field (e.g. BigDecimal)

Reported by: Andreas Assigned to: core
Priority: normal Milestone: 1.2.5
Component: ActionPack Version: 1.2.1
Severity: major Keywords: in_place_editor
Cc:

Description

This bug was introduced with Rails 1.2.

How to reproduce: Use in_place_edit_for with a non-string field, e.g. BigDecimal or Float.

Backtrace:

NoMethodError (undefined method `size' for #<BigDecimal:b70dd614,'0.0',4(8)>):
    /usr/local/ruby-1.8.5/lib/ruby/gems/1.8/gems/actionpack-1.13.1/lib/action_controller/cgi_process.rb:227:in `set_content_length!'
    /usr/local/ruby-1.8.5/lib/ruby/gems/1.8/gems/actionpack-1.13.1/lib/action_controller/cgi_process.rb:186:in `out'
    /usr/local/ruby-1.8.5/lib/ruby/gems/1.8/gems/rails-1.2.1/lib/dispatcher.rb:41:in `dispatch'
    /opt/lsws/fcgi-bin/RailsRunner.rb:12

Patch:

--- in_place_editing.rb.orig    2007-01-28 18:11:18.000000000 +0100
+++ /usr/local/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.1/lib/action_controller/macros/in_place_editing.rb    2007-01-28 18:11:45.000000000 +0100
@@ -24,7 +24,7 @@
           define_method("set_#{object}_#{attribute}") do
             @item = object.to_s.camelize.constantize.find(params[:id])
             @item.update_attribute(attribute, params[:value])
-            render :text => @item.send(attribute)
+            render :text => @item.send(attribute).to_s
           end
         end
       end

Change History

(in reply to: ↑ description ) 02/15/07 01:15:26 changed by DerGuteMoritz

I totally confirm this! Patch ASAP, please :)

02/21/07 18:14:26 changed by DanielSmedegaardBuus

Ticket #7224 that fixes this does not fix the other similar bug which concerns blanking out integer/float/bigdecimal fields to set them to nil. If you try this, you get an error like this, even though the value is properly set to nil in the database, and a refresh of the page confirms just that.

ActionController::MissingTemplate (Missing template C:/railsapp/polybook/config/../app/views/items/set_item_discount_price.rhtml):

C:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.2/lib/action_controller/base.rb:1205:in `assert_existence_of_template_file' C:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.2/lib/action_controller/base.rb:804:in `render_file' C:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.2/lib/action_controller/base.rb:777:in `render_with_no_layout' C:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.2/lib/action_controller/layout.rb:244:in `render_without_benchmark' C:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.2/lib/action_controller/benchmarking.rb:50:in `render' C:/ruby/lib/ruby/1.8/benchmark.rb:293:in `measure' C:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.2/lib/action_controller/benchmarking.rb:50:in `render' C:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.2/lib/action_controller/macros/in_place_editing.rb:27:in `set_item_discount_price' C:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.2/lib/action_controller/base.rb:1095:in `send' C:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.2/lib/action_controller/base.rb:1095:in `perform_action_without_filters' C:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.2/lib/action_controller/filters.rb:632:in `call_filter' C:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.2/lib/action_controller/filters.rb:638:in `call_filter' C:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.2/lib/action_controller/filters.rb:438:in `call' C:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.2/lib/action_controller/filters.rb:637:in `call_filter' C:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.2/lib/action_controller/filters.rb:619:in `perform_action_without_benchmark' C:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.2/lib/action_controller/benchmarking.rb:66:in `perform_action_without_rescue' C:/ruby/lib/ruby/1.8/benchmark.rb:293:in `measure' C:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.2/lib/action_controller/benchmarking.rb:66:in `perform_action_without_rescue' C:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.2/lib/action_controller/rescue.rb:83:in `perform_action' C:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.2/lib/action_controller/base.rb:430:in `send' C:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.2/lib/action_controller/base.rb:430:in `process_without_filters' C:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.2/lib/action_controller/filters.rb:624:in `process_without_session_management_support' C:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.2/lib/action_controller/session_management.rb:114:in `process' C:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.2/lib/action_controller/base.rb:330:in `process' C:/ruby/lib/ruby/gems/1.8/gems/rails-1.2.2/lib/dispatcher.rb:41:in `dispatch' C:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel/rails.rb:78:in `process' C:/ruby/lib/ruby/1.8/thread.rb:135:in `synchronize' C:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel/rails.rb:76:in `process' C:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel.rb:618:in `process_client' C:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel.rb:617:in `each' C:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel.rb:617:in `process_client' C:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel.rb:736:in `run' C:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel.rb:736:in `initialize' C:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel.rb:736:in `new' C:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel.rb:736:in `run' C:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel.rb:720:in `initialize' C:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel.rb:720:in `new' C:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel.rb:720:in `run' C:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel/configurator.rb:271:in `run' C:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel/configurator.rb:270:in `each' C:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel/configurator.rb:270:in `run' C:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/bin/mongrel_rails:127:in `run' C:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel/command.rb:211:in `run' C:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/bin/mongrel_rails:243 C:\ruby\bin\mongrel_rails:18:in `load' C:\ruby\bin\mongrel_rails:18 -e:3:in `load' -e:3

Rendering C:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.2/lib/action_controller/templates/rescues/layout.rhtml (500 Internal Error)

04/11/07 19:43:18 changed by orangechicken

I think that the similar bug mentioned in the comments may be caused by the options that are passed to render by set_<model>_<attribute>. The params, if you're clearing the attribute, is { :text => nil }. This likely fails some test somewhere in the render chain and says "since :text is nil then I must need to render a template but the template is missing". Searching more since I'm running into the same problem.

Oh, and this still happens in 1.2.3

04/11/07 20:08:54 changed by orangechicken

I opened a new bug for the MissingTemplate bug: http://dev.rubyonrails.org/ticket/8051

10/08/07 00:12:08 changed by bitsweat

(In [7782]) Fix setter action with non-string fields. References #7418.

10/08/07 00:13:37 changed by bitsweat

(In [7783]) Fix in place editor's setter action with non-string fields. References #7418.

10/08/07 00:16:24 changed by bitsweat

  • status changed from new to closed.
  • resolution set to fixed.
  • milestone changed from 1.x to 1.2.5.