bburridg-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2009-Feb-04 17:40 UTC
Custom module for ActionController no longer works in Rails 2.2
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 -- 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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2009-Feb-04 17:46 UTC
Re: Custom module for ActionController no longer works in Rails 2.2
On 4 Feb 2009, at 17:40, bburridg-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org 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 http://www.spacevatican.org/2008/11/21/environment-rb-and-requiring-dependencies ? Fred> Brian Burridge > Agile Nomads > 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 > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
bburridg-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2009-Feb-04 21:07 UTC
Re: Custom module for ActionController no longer works in Rails 2.2
That did the trick. Thanks Fred!! Brian Burridge Agile Nomads www.rubyrailsreview.com On Feb 4, 12:46 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 4 Feb 2009, at 17:40, bburr...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org 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? > > Maybehttp://www.spacevatican.org/2008/11/21/environment-rb-and-requiring-d... > ? > > Fred > > > Brian Burridge > > Agile Nomads > >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]) > > -JplMmCmmLAhgoHlPtYpdqQ@public.gmane.org("#{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--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Julian Leviston
2009-Feb-05 00:30 UTC
Re: Custom module for ActionController no longer works in Rails 2.2
An error backtrace would be really helpful. Blog: http://random8.zenunit.com/ Learn rails: http://sensei.zenunit.com/ On 05/02/2009, at 4:40 AM, "bburridg-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org" <bburridg-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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? > > Brian Burridge > Agile Nomads > 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 > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---