Matthew Fournier
Matthew Fournier

Reputation: 1155

Rails: Create a select box that shows images, passes path

So, I have a rails controller that has a @images set, which has the paths for the images I want to select from, ready to use in image_tag. The table for this object has a field for image_path. In the new view for this object, I want to have a select box that displays each image from @images and passes the text of that into the form, where it will be saved to the object's database.

Right now, I have code that makes a select box showing the filename:

= f.select :image_path, @images

and code that can show all of the images

[email protected] do |image|
  = image_tag image

What I want is for the select box to show the images and pass the paths as it already does.

Upvotes: 0

Views: 1636

Answers (1)

JamesDullaghan
JamesDullaghan

Reputation: 1340

This is not possible with the default rails select tags, though there is a jquery plugin called jquery image dropdown See this SO POST for more information.

Upvotes: 1

Related Questions