``Hobo::Controller::Model.find_or_paginate`` overwrites ``finder.find``
Reported by Tomoaki Hayasaka | October 18th, 2010 @ 04:15 AM
Hobo::Controller::Model.find_or_paginate
does
finder.send(:scope, :find)
, which overwrites
finder.find
(e.g. User.find
, you may find
a warning about it in the log), and that causes many wierd
results.
Reproducing:
config.cache_classes = true
class UsersController < ApplicationController
hobo_user_controller
auto_actions :all
end
First time you go to /users, there's nothing special. But
re-visiting /users gets "undefined method `guest?' for
#<ActiveRecord::Relation:0xb2c3458>
".
In rails3, ActiveRecord::Base.scope
is still
defined but its meaning is completely different.
Fix:
diff --git a/hobo/lib/hobo/controller/model.rb b/hobo/lib/hobo/controller/model.rb
index 2ef9c28..bb68d64 100644
--- a/hobo/lib/hobo/controller/model.rb
+++ b/hobo/lib/hobo/controller/model.rb
@@ -451,7 +451,7 @@ module Hobo
do_pagination = options.delete(:paginate) && finder.respond_to?(:paginate)
finder = Array.wrap(options.delete(:scope)).inject(finder) { |a, v| a.send(*Array.wrap(v).flatten) }
- options[:order] = :default unless options[:order] || finder.send(:scope, :find)._?[:order]
+ options[:order] = finder.default_order unless options[:order] || finder.try.order_values.present?
if do_pagination
options.reverse_merge!(:page => params[:page] || 1)
@@ -734,7 +734,7 @@ module Hobo
def hobo_completions(attribute, finder, options={})
options = options.reverse_merge(:limit => 10, :param => :query, :query_scope => "#{attribute}_contains")
- finder = finder.limit(options[:limit]) unless finder.send(:scope, :find, :limit)
+ finder = finder.limit(options[:limit]) unless finder.try.limit_value
begin
finder = finder.send(options[:query_scope], params[options[:param]])
Test:
config.cache_classes = true
class User < ActiveRecord::Base
hobo_user_model # Don't put anything above this
fields do
username :string, :required, :unique
email_address :email_address, :login => true
timestamps
end
def name; sprintf("%02d - %s - %s", id, username, email_address); end
def administrator?; true; end
def create_permitted?; true; end
def update_permitted?; true; end
def destroy_permitted?; true; end
def view_permitted?(field); true; end
end
class UsersController < ApplicationController
hobo_user_controller
def index
::User.send(:set_default_order, (params[:by] || :email_address))
hobo_index
end
index_action :using_option do
hobo_index ::User, :order => (params[:by] || :email_address)
render :index
end
index_action :using_hobo_scope do
hobo_index ::User.order(params[:by] || :email_address)
render :index
end
index_action :using_ar_scope do
hobo_index ::User.order_by(params[:by] || :email_address)
render :index
end
end
names = (0..35).map{|i| "A User #{i.to_s(36)}"}.shuffle
emails = (0..35).map{|i| "user_#{i.to_s(36)}@example.com"}.shuffle
(0..35).each { |i| User.create!(:username => names[i], :email_address => emails[i])}
Comments and changes to this ticket
-
Domizio Demichelis October 20th, 2010 @ 01:47 PM
- State changed from new to resolved
-
otis October 25th, 2022 @ 02:48 AM
I visit your blog regularly and recommend among us it to all of those who wanted to enhance their knowledge with ease. The style of writing is excellent and also the content is top-notch. Thanks for that shrewdness you provide the readers!
-
otis October 25th, 2022 @ 02:48 AM
Thanks for the information, framed will try to figure it out for more. Keep sharing such informative post keep suggesting such post.
-
lorde123 October 27th, 2022 @ 07:53 AM
wordle is a famous crossword game inspired by the matching game Mastermind. It was created and developed by a Welsh software engineer named Josh Wardle, owned and published by The New York Times
-
lorde123 October 27th, 2022 @ 07:54 AM
shell shockers - A great product from the blue wizard. Massively multiplayer online shooting game that appeals to everyone with its simple graphics and interesting maps.
-
Daniel Williams October 31st, 2022 @ 07:02 AM
I really like the information you share. Thanks to that, getting over it I know many more interesting and useful things.
-
Amity Sherlock December 17th, 2022 @ 09:14 AM
The information you share is very good and interesting, thanks to that, I know more useful things. Keep posting interesting things and I will keep an eye on your posts. drift boss
Please Sign in or create a free account to add a new ticket.
With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
People watching this ticket
Tags
Referenced by
- 833 ``Hobo::Controller::Model.find_or_paginate`` overwrites ``finder.find`` (from [006309aa0a2bc5937a4fa8b95d6223a1f24dad87]) [#833 s...