Kashia asked:

Select from Og Collection?

What is an easy way make a select statement of Og collection?

Lets say I have 5 Tags, and I want a easy way just to select one of those tags.

class Tag
  property :name, String
end

<select name="tag_oid">
<option value="1">First Tag Name</option>
<!-- ... -->
</select>

Something like that above would be cool!

(1 attempts)

manveru answered:

class Tag
  property :name, String

  def to_s
    @name
  end
end

def tag_select
  tags = Tag.all
  %{<select name="tag_oid">} +
  tags.map{ |tag| %{<option value="#{tag.oid}">#{tag}</option>} }.join +
  %{</select>}
end

def select_for(obj, prop)
  %{<select name="#{obj.class.name.methodize}_oid">} +
  obj.map{ |o| %{<option value="#{o.oid}">#{o.send(prop)||o}</option>} }.join +
  %{</select>}
end

Use it like:

#{tag_select}

Oh, and i know that this doesn't really answer that question, but i just can't figure out what you mean by 'select statement of Og collection'...

The other one is just for fun... ;)

Rating: 4