I have a working 2.3.5 rails app that I am upgrading to rails 3 beta 4.
I had monkey-patched a couple of class methods to the Activerecord::Base
class and put it in the lib directory. This has worked fine for ages in
2.3.x, but Rails 3 is refusing to even recognize it. I get undefined
method error from my controller method. Here are the details:
NoMethodError in ClientsController#index
undefined method `my_search'' for #<Class:0x7f08d251dee8>
Rails.root: /home/bruparel/rr_work/file_manager3
Application Trace | Framework Trace | Full Trace
app/controllers/clients_controller.rb:17:in `index''
Here is the line number 17 in the clients_controller.rb file above:
@clients = Client.my_search(params[:search], params[:page],
get_search_field, user_role, perms)
As you can see, it calls my_search method which I have defined in the
Rails.root/lib/active_record_extensions.rb file as follows:
module ActiveRecord
class Base
def self.my_search(search, current_page, search_field, user_role,
perms)
if search.blank?
if user_role == ''staff''
paginate(:all, :conditions => ["id in (?)", perms], :page
=>
current_page || 1, :per_page => 10)
else
paginate(:all, :page => current_page || 1, :per_page => 10)
end
else
if user_role == ''staff''
paginate(:all, :conditions => ["#{search_field} LIKE ? and id
in (?)", "%#{search}%", perms],
:order => search_field, :page => current_page || 1,
:per_page => 10)
else
paginate(:all, :conditions => ["#{search_field} LIKE ?",
"%#{search}%"], :order => search_field,
:page => current_page || 1, :per_page => 10)
end
end
end
end
I don''t understand why does Rails refuse to find it. I looked up the
Rails 3 documenation, as far as I can tell, the organization of
ActiveRecord module and the Base class has not changed. Why is this
then happening?
Thanks.
Bharat
--
Posted via http://www.ruby-forum.com/.
--
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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.