# Custom module for ActionController no longer works in Rails 2.2

**URL:** <https://www.ruby-forum.com/t/custom-module-for-actioncontroller-no-longer-works-in-rails-2-2/159454>\
**Category:** Rails\
**Created:** [February 4, 2009, 6:41pm UTC](https://www.ruby-forum.com/t/custom-module-for-actioncontroller-no-longer-works-in-rails-2-2/159454 "2009-02-04T18:41:34Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [February 4, 2009, 6:41pm UTC](https://www.ruby-forum.com/t/custom-module-for-actioncontroller-no-longer-works-in-rails-2-2/159454/1 "2009-02-04T18:41:34Z")

</div>

I am using some code for in place JS editing with validation, that  
worked up until Rails 2.2. After upgrade, the method can’t be find, so  
apparently its not overridge the right class or isn’t being included  
as before. It is currently being included via a require statement in  
environment.rb. The code is below. Any suggestions?

Brian Burridge  
Agile Nomads  
[www.rubyrailsreview.com](http://www.rubyrailsreview.com)

– code –

module ActionController  
module Macros  
module CustomInPlaceEditing  
def self.included(base)  
base.extend(ClassMethods)  
end

```
module ClassMethods
 def in_place_edit_with_validation_for(object, attribute)
  define_method("set_#{object}_#{attribute}") do
   klass = object.to_s.camelize.constantize
  @item = klass.find(params[:id])
  @item.send("#{attribute}=", params[:value])
   if @item.save
    render :update do |page|
     page.replace_html("#{object}_#{attribute}_#{params[:id]}

```

_in\_place\_editor",  
 @item.send(attribute))  
end  
else  
render :update do |page|  
page.alert(@item.errors.full\_messages.join(“\n”))  
klass.query\_cache.clear\_query\_cache if  
klass.method\_defined?:query\_cache  
 @item.reload  
page.replace\_html("#{object}_#{attribute}\_#{params[:id]}  
\_in\_place\_editor",  
@item.send(attribute))  
end  
end  
end  
end  
end  
end  
end  
end

ActionController::Base.class\_eval do  
include ActionController::Macros::CustomInPlaceEditing  
end

module ActionView  
module Helpers  
class InstanceTag  
def to\_content\_tag(tag\_name, options = {})  
content\_tag(tag\_name, html\_escape(value(object)), options)  
end

```
end

```

end  
end

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [February 4, 2009, 6:50pm UTC](https://www.ruby-forum.com/t/custom-module-for-actioncontroller-no-longer-works-in-rails-2-2/159454/2 "2009-02-04T18:50:27Z")

</div>

On 4 Feb 2009, at 17:40, removed\_email\_address@domain.invalid wrote:

> I am using some code for in place JS editing with validation, that  
> worked up until Rails 2.2. After upgrade, the method can’t be find, so  
> apparently its not overridge the right class or isn’t being included  
> as before. It is currently being included via a require statement in  
> environment.rb. The code is below. Any suggestions?

Maybe

> **[environment.rb and requiring dependencies - Space Vatican](https://www.spacevatican.org/2008/11/21/environment-rb-and-requiring-dependencies/)**
>
> In the before time, the bottom of most of my apps’ environment.rb was an unholy mess. Inflector rules, requiring of various libraries or gems, …

?

Fred

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [February 4, 2009, 10:08pm UTC](https://www.ruby-forum.com/t/custom-module-for-actioncontroller-no-longer-works-in-rails-2-2/159454/3 "2009-02-04T22:08:40Z")

</div>

That did the trick. Thanks Fred!!

Brian Burridge  
Agile Nomads  
[www.rubyrailsreview.com](http://www.rubyrailsreview.com)

On Feb 4, 12:46 pm, Frederick C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [February 5, 2009, 1:31am UTC](https://www.ruby-forum.com/t/custom-module-for-actioncontroller-no-longer-works-in-rails-2-2/159454/4 "2009-02-05T01:31:00Z")

</div>

An error backtrace would be really helpful.

Blog: [http://random8.zenunit.com/](http://random8.zenunit.com/)  
Learn rails: [http://sensei.zenunit.com/](http://sensei.zenunit.com/)

On 05/02/2009, at 4:40 AM, “removed\_email\_address@domain.invalid” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
