OK, so I got a little further. I used the <select> tag and am
searching for menu entries, but am having trouble populating the list.
I have ancestry set up properly and migrated, and here's my (relevant)
model code:
fields do
name :string, :unique, :name => true
ancestry :string, :index => true
timestamps
end
belongs_to :post
has_ancestry
Then, I created a merged form in application.dryml which looks like
this:
<extend tag="form" for="MenuEntry">
<old-form merge multipart>
<field-list: fields="name, post, parent_id">
<parent-id-view:>
<% @menu_entries = MenuEntry.all %>
<if test="&@menu_entries">
<select options="&@menu_entries"/>
</if>
<else>
<select disabled><option>No Parents Available</option></
select>
</else>
</parent-id-view:>
</field-list:>
</old-form>
</extend>
Now, when I create the first menu entry, I get the "No Parents
Available" entry (disabled), and I can create other entries as well.
However, after I create the first, I would expect to have a list of
all menu entries in the drop down. If I put a <% puts... %> statement
I get all the menu_entries that are saved to the db. However, those
menu entries do not show up in the drop down.
I'm grasping at straws here, but do I need to iterate and get the
names of the entries (I have a field set for name in the model as you
can see above)? Is something not "translating" correctly since I am
not using the <select-one> tag (which won't work since this isn't a
belongs_to relationship)?
Any help would be appreciated very much. I feel like I'm almost
there!!! :)
On Sep 30, 1:27 am, Banjoey <[email protected]> wrote:
> OK, I have installed the Ancestry gem, migrated the db fields, and am
> working on my very first recipe to contribute to the cookbook.
> However, I've hit a roadblock and need some help...
>
> I have a model that I'm going to use for a menu system, and the model
> is called MenuEntry. It just has a name :string and the
> ancestry :string fields, plus an associated belongs_to :post
> relationship. I think I'd like to set it up to where you simply pick a
> parent menu entry in the new/edit forms. If I understand the ancestry
> gem correctly I'll just need to provide the user with a drop down list
> of all the available menu_entries and then pass the selected one to
> the new method of the controller when creating this one.
>
> 1) How do I create a drop down of all the menu entries? It looks to me
> like <select-one> would be the best way to go, but is it only usable
> on models that are set up to have a belongs_to relationship, or can I
> override that with something like <select-one
> entries="#{MenuEntry.all}">... or something like that?
>
> 2) Once I get that, can I pass the selected menu_entry to the new
> controller method and do what I need with it? I think the code I'd
> need in a non-hobo app would be something like this: @menu_entry =
> MenuEntry.new(:parent_id => params[:parent_id]) but I was wondering if
> I could pass those parameters into hobo_new like this:
> hobo_new :parent_id => params[:parent_id]
>
> I think the :parent_id is set up when you declare the model with
> has_ancestry, so I assume that means it is "hidden" to hobo, and all
> the information is stored in that string field anyway. Any ideas on
> where I can look?
>
> Thanks,
> Joey
--
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.