Hey all,
this order_by method right here is throwing an exception:
@resource_model.order_by(@order_field)
The exception is "TypeError (Cannot visit Category):"
I think it''s returning this:
#<ActiveRecord::Relation:0x000001038701f0>
I have no clue why. It''s supposed to be returning a string like
''controller asc''.
This is the lead up to the error:
def find_options
extract_pagination
extract_order
opts = {:page => @will_paginate_page, :per_page =>
@will_paginate_per_page, :order => @will_paginate_order}
opts.merge(additional_options)
end
def additional_options
{}
end
def extract_pagination
@will_paginate_page = params[:page] || 1
@will_paginate_per_page = params[:per_page] || 20
end
def extract_order
if params[:order].present?
@order_field = params[:order]
end
@will_paginate_order = @resource_model.order_by(@order_field)
end
#my category model inherits from restfulmodel.rb:
def self.order_by(field)
field = field.to_s
if field.blank?
return default_order ? order_by(default_order) : scoped(nil) #if
returned value of default_order call exists, self-invoke order_by
end
scope = field.starts_with?(''-'') ?
''descend_by_'' + field.from(1) :
''ascend_by_'' + field
send(scope)
end
#then my category model has this:
def self.default_order
''controller''
end
scope :ascend_by_controller, :order => ''controller asc''
Something is flawed with that order_by method. It''s not sending
ascend_by_controller to the category model and then returning the value
of the scope :ascend_by_controller. Am I missing something here?
@will_paginate_order should hold a string like ''controller
asc''
Thanks for response.
--
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.