In the context of a model ‘Device’ …. has_many :device_movements
I am trying to sort on a field of a record belonging to DeviceMovements
in devices_controller (I have unsuccessfully tried a number of things as
per the comments): at the moment I have denormalised the model and am
sorting on last_move..
*hobo_model_controller
auto_actions :all #, :except => :index
*
*
def index
hobo_
def index
hobo_index Device.tech_view.apply_scopes( :search => [params[:search],
:name],
# This is a Ruby gotcha - if you're going to put anything outside of
[a-zA-Z0-9_]
# in a symbol value, you need to quote it: eg
:'device_movements.last.created_at'
# :joins => :device_movements, # Check what this does; shows only devices
with movements; investigate further..
:order_by => parse_sort_param(:name, :product, :last_move,
'device_movements.last.created_at'))
#
Device.include(:device_movements).order_by(parse_sort_param("device_movements.last.created_at")))
end*
and in ../views/devices/index.dryml :
*<index-page>*
*<collection: replace>*
*<div>*
*<table-plus fields="this, product, last_move, age,
device_movements.last.created_at, tech_status_changes.reverse.rotate.first"
>*
*<last-move-heading-link:>Last Movement</last-move-heading-link:>*
*<last-move-view:><view format="%d %B %Y"/></last-move-view:>*
*<age-heading:>Days Waiting</age-heading:>*
*<device-movements-last-created-at-heading-link:>Dernier
Move</device-movements-last-created-at-heading-link:>*
*<device-movements-last-created-at-view:><view format="%d %B
%Y"/></device-movements-last-created-at-view:>*
*<tech-status-changes-reverse-rotate-first-heading:>Last
Status</tech-status-changes-reverse-rotate-first-heading:>*
*<controls:>*
*<transition-buttons/>*
*</controls:>*
*</table-plus>*
*</div>*
*</collection:>*
*</index-page>*
Can sorting on ‘*device_movements.last.created_at*’ be done or this is
viewed as a calculated field on which we cannot sort ?
--
You received this message because you are subscribed to the Google Groups "Hobo
Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/hobousers?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.