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

Ticket #8051 (closed defect: duplicate)

Opened 1 year ago

Last modified 9 months ago

[PATCH] In place editing fails when attempting to clear the value

Reported by: orangechicken Assigned to: core
Priority: high Milestone: 1.2 regressions
Component: ActionPack Version: 1.2.3
Severity: major Keywords:
Cc:

Description

When trying to clear a value using in-place editing, an ActionController::MissingTemplate error is raised.

The cause is because the options given to #render is { :text => nil } (since params[:value] is nil when sending a blank value via the Javascript). Those options cause various problems eventually leading the render mechanism to believe, incorrectly, it should render a view template for the set_<model>_<attribute> method.

Here's the params the method receives: Parameters: {"action"=>"set_set_title", "id"=>"48597", "controller"=>"entries"}

Here's a backtrace:

/var/www/apps/eachday/releases/20070411021523/vendor/rails/actionpack/lib/action_controller/base.rb:1206:in `assert_existence_of_template_file'
/var/www/apps/eachday/releases/20070411021523/vendor/rails/actionpack/lib/action_controller/base.rb:805:in `render_file'
/var/www/apps/eachday/releases/20070411021523/vendor/rails/actionpack/lib/action_controller/base.rb:778:in `render_with_no_layout'
/var/www/apps/eachday/releases/20070411021523/vendor/rails/actionpack/lib/action_controller/layout.rb:244:in `render_without_benchmark'
/var/www/apps/eachday/releases/20070411021523/vendor/rails/actionpack/lib/action_controller/benchmarking.rb:50:in `render'
/usr/lib/ruby/1.8/benchmark.rb:293:in `measure'
/var/www/apps/eachday/releases/20070411021523/vendor/rails/actionpack/lib/action_controller/benchmarking.rb:50:in `render'
/var/www/apps/eachday/releases/20070411021523/app/controllers/sets_controller.rb:22:in `set_set_title'
/var/www/apps/eachday/releases/20070411021523/vendor/rails/actionpack/lib/action_controller/base.rb:1096:in `perform_action_without_filters'

30 irrelevant lines removed for brevity ...

It shouldn't get to render_file, I believe.

Attachments

macros_in_place_editing.patch (0.5 kB) - added by luminousbit on 06/16/07 18:27:11.
Patch per orangechicken

Change History

04/11/07 20:05:17 changed by orangechicken

The question is, is this a regression with Rails or with Prototype/Scriptaculous? Should a blank string be sent as :value by the Javascript? If anyone has the ability to clear their in-place editable fields, can you check if the params hash contains an empty :value?

04/11/07 20:18:36 changed by orangechicken

Yeah, the problem is definitely that params[:value] is nil because ActionController::Base#render checks if text = options[:text] which if { :text => nil }, returns nil and doesn't render_text as it should.

Would it be better to check if options.has_key?(:text) ?

04/11/07 20:21:11 changed by orangechicken

#render hasn't changed in quite a while, so the change is more likely to have come from the prototype/scriptaculous side.

04/11/07 20:23:26 changed by orangechicken

Though, it still doesn't really solve the in-place editing problem. Because you likely *do* want to set the value to NULL in the database and not just an empty string.

So we're back to needing a patch for handling nil values for text. I think the simplest patch for this would be to change the in_place_edit_for-generated method to render :text => @item.send(attribute) || ''

That ought to solve the problem.

04/11/07 20:24:33 changed by orangechicken

Yeah, that fixes it. I'll make a patch.

06/16/07 18:27:11 changed by luminousbit

  • attachment macros_in_place_editing.patch added.

Patch per orangechicken

06/16/07 18:28:30 changed by luminousbit

I attached the patch that orangechicken suggested. However, given that this function is deprecated and will be moved to a plugin, maybe it would be better to simply close out the ticket?

06/16/07 18:28:53 changed by luminousbit

  • summary changed from In place editing fails when attempting to clear the value to [PATCH] In place editing fails when attempting to clear the value.

08/07/07 09:31:00 changed by andreasror

It's better to use to_s instead of "" because this also fixes a bug with BigNums: #7418

10/08/07 00:06:59 changed by bitsweat

  • status changed from new to closed.
  • resolution set to duplicate.