El Friday 08 May 2009 02:49:42 JannaB escribió:
> I have have an array of Strings which are filenames of image files I
> would like to use to populate a combobox in Form view (for editing a
> field called 'graphic'). In other words, I would like to have the
> combobox display the images as selections.
>
> This is accomplished in straight html as:
> <.option style = "background-image : url(path_to_image);" ...>
> For each image.
>
> Does anyone know how to override in my helper file the
> def graphic_form_column (record, input_name)
> So that it
> A. Creates a combobox for the field's control -and-
> B. Populates it in a manner that would create the requisite html as I
> have posted above such that it will display the images as selections
> within the combox?
>
> Thanks so much, Janna
>
>
To create a select in rails you have two ways: select and select_tag
select use options_for_select to convert the choices array into option tags,
and you can't set style with background-image. So you have to use select_tag.
Select_tag needs you build the option tags (and you must to mark the selected
option). You must set the name attribute with the second argument received in
order to ActiveScaffold saves your form.
def graphic_form_column(record, input_name)
options = STRING_ARRAY.inject('') do |opts, image|
opts + content_tag(:option, '', :style => "background-image:
url(#{path_to_image "icons/#{image}"})", :value => image
end
select_tag(input_name, options)
end
--
Sergio Cambra .:: entreCables S.L. ::.
Nicolás Guillén 6, locales 2 y 3. 50.018 Zaragoza
T) 902 021 404 F) 976 52 98 07 E) [email protected]
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"ActiveScaffold : Ruby on Rails plugin" 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/activescaffold?hl=en
-~----------~----~----~----~------~----~------~--~---