Select menu not using model ids as values

18 views
Skip to first unread message

tonym

unread,
Jan 14, 2013, 6:38:06 PM1/14/13
to hobo...@googlegroups.com
Hi All,
Been scratching my head over this one for a while.
I'm using a select menu as a set of filters.  nothing special, just passing them as params...

<def tag="searchform">
  <form class="filter-menu searchform" action="/categories/" method="GET" >
    <select-menu name="category" selected='&selected' first-option="All Categories" options="&Category.all" />
    <select-menu name="area" selected='&selected' first-option="Anywhere In Sheffield" options="&LocalArea.all" />
    <select-menu name="day" selected='&selected' options="&day_filter_options" />
    <button type="submit" id="main_srch" class="btn">Search</button>
  </form>
</def>

Problem is, the select menu values are being populated with the name string, not the model's id.
Works perfectly for the hash pairs I've built for the day_filter_options, but not for the models.

Any help would be greatly appreciated.

Cheers, Anthony.

Ignacio Huerta

unread,
Jan 15, 2013, 1:29:51 AM1/15/13
to hobo...@googlegroups.com
Hi,

When passing custom options to select_menu I usually use "map". Try this
and see if it works:

<select-menu name="category" selected='&selected' first-option="All
Categories" options="&Category.all.map{|category|
[category.name, category.id]}"" />

There's also an old post discussing something similar:
https://groups.google.com/forum/#!topic/hobousers/yIz5I7k3Zoo

Regards,
Ignacio

El 15/01/13 00:38, tonym escribi�:
> Hi All,
> Been scratching my head over this one for a while.
> I'm using a select menu as a set of filters. nothing special, just
> passing them as params...
>
> <def tag="searchform">
> <form class="filter-menu searchform" action="/categories/" method="GET" >
> <select-menu name="category" selected='&selected' first-option="All
> Categories" options="&Category.all" />
> <select-menu name="area" selected='&selected'
> first-option="Anywhere In Sheffield" options="&LocalArea.all" />
> <select-menu name="day" selected='&selected'
> options="&day_filter_options" />
> <button type="submit" id="main_srch" class="btn">Search</button>
> </form>
> </def>
>
> Problem is, the select menu /values/ are being populated with the name
> string, not the model's id.
> Works perfectly for the hash pairs I've built for the
> day_filter_options, but not for the models.
>
> Any help would be greatly appreciated.
>
> Cheers, Anthony.
>
> --
> You received this message because you are subscribed to the Google
> Groups "Hobo Users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/hobousers/-/dhlNUczdtesJ.
> To post to this group, send email to hobo...@googlegroups.com.
> To unsubscribe from this group, send email to
> hobousers+...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/hobousers?hl=en.

--
Ignacio Huerta Arteche
http://www.ihuerta.net
Tel�fono: 0034 645 70 77 35
Email realizado con software libre

tonym

unread,
Jan 15, 2013, 4:13:03 AM1/15/13
to hobo...@googlegroups.com

Thankyou! for such a quick reply.  That's exactly what I was looking for.

Cheers, Anthony.


On Tuesday, January 15, 2013 6:29:51 AM UTC, Ignacio Huerta wrote:
Hi,

When passing custom options to select_menu I usually use "map". Try this
and see if it works:

<select-menu name="category" selected='&selected' first-option="All
Categories" options="&Category.all.map{|category|
[category.name, category.id]}"" />

There's also an old post discussing something similar:
https://groups.google.com/forum/#!topic/hobousers/yIz5I7k3Zoo

Regards,
Ignacio

El 15/01/13 00:38, tonym escribi�:
Tel�fono: 0034 645 70 77 35

Ignacio Huerta

unread,
Jan 15, 2013, 7:04:11 AM1/15/13
to hobo...@googlegroups.com, tonym
You are welcome!

El 15/01/13 10:13, tonym escribi�:
>
> Thankyou! for such a quick reply. That's exactly what I was looking for.
>
> Cheers, Anthony.
>
>
> On Tuesday, January 15, 2013 6:29:51 AM UTC, Ignacio Huerta wrote:
>
> Hi,
>
> When passing custom options to select_menu I usually use "map". Try
> this
> and see if it works:
>
> <select-menu name="category" selected='&selected' first-option="All
> Categories" options="&Category.all.map{|category|
> [category.name <http://category.name>, category.id
> <http://category.id>]}"" />
>
> There's also an old post discussing something similar:
> https://groups.google.com/forum/#!topic/hobousers/yIz5I7k3Zoo
> <https://groups.google.com/forum/#!topic/hobousers/yIz5I7k3Zoo>
>
> Regards,
> Ignacio
>
> El 15/01/13 00:38, tonym escribi�:
> <https://groups.google.com/d/msg/hobousers/-/dhlNUczdtesJ>.
> > To post to this group, send email to hobo...@googlegroups.com
> <javascript:>.
> > To unsubscribe from this group, send email to
> > hobousers+...@googlegroups.com <javascript:>.
> > For more options, visit this group at
> > http://groups.google.com/group/hobousers?hl=en
> <http://groups.google.com/group/hobousers?hl=en>.
>
> --
> Ignacio Huerta Arteche
> http://www.ihuerta.net
> Tel�fono: 0034 645 70 77 35
> Email realizado con software libre
>
> --
> You received this message because you are subscribed to the Google
> Groups "Hobo Users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/hobousers/-/Jf892m31XS8J.
> To post to this group, send email to hobo...@googlegroups.com.
> To unsubscribe from this group, send email to
> hobousers+...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/hobousers?hl=en.

--
Ignacio Huerta Arteche
http://www.ihuerta.net
Tel�fono: 0034 645 70 77 35
Reply all
Reply to author
Forward
0 new messages