After scouring through the group I found several older posts on how to
make this work properly, not sure if it's documented elsewhere so I'll
put it all here for completeness.
For a Hobo 1.3 application where you want to use an enum-string to
populate a <filter-menu>, you must do the following (using the Agility
project story model with status filtering as an example):
In the model ...
class Story < ActiveRecord::Base
hobo_model # Don't put anything above this
Status =
HoboFields::Types::EnumString.for(:new, :accepted, :discussion, :implementation)
fields do
title :string
body :text
status Story::Status
timestamps
end
...
In the controller, setup the filter:
class StoriesController < ApplicationController
hobo_model_controller
auto_actions :all
def index
hobo_index Story.apply_scopes(:status_is => params[:status])
end
...
And finally at the view layer (index.dryml for my case) ...
...
<append-header:>
<div class="filter">
Display stories by status: <filter-menu param-name="status"
options="&Story::Status.values"/>
</div>
</append-header:>
...
I hope that this helps someone else out there. It would be beneficial
in my mind to add this to the Agility tutorial, or perhaps it's
already well documented and I just looked in the wrong places :-)
On Oct 18, 5:06 pm, Jeremy Savoy <[email protected]> wrote:
> For the <filter-menu> example in the Agility tutorial, the following
> code is used to add the filter menu to the Project show page, to
> filter stories by their status:
>
> <prepend-header:>
> <div class="filter">
> Display by status: <filter-menu param-name="status"
> options="&StoryStatus.all"/>
> </div>
> </prepend-header:>
>
> These statuses are contained in the model StoryStatus. However,
> previously the story statuses were stored in the story model as ...
>
> status enum_string(:new, :accepted, :discussion, :implementation)
>
> My question to the group is, how do I modify the <filter-menu> tag
> above to make use of the status field in the story model, versus
> &StoryStatus.all ?
>
> I've tried changing the following with no success:
>
> options="&Story.status" ----> fails, NoMethodError
> options="&Story.status.all" ----> fails, NoMethodError
> options="&Story.all" ---> succeeds, but the filter list is the entire
> list of stories -- not what I wanted obviously
--
You received this message because you are subscribed to the Google Groups "Hobo
Users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/hobousers?hl=en.