I have gif files in my public/images/posticons directory, I want to read their filenames without the extension to list the files as a set of radio buttons in the form: [code]<%= radio_button("thread", "posticon", imgname) %> <img src="/images/posticons/<%= imgname%>.gif" alt="" />[code] Would I be saving myself a lot of time and server resources by just saving all of the posticons into the database instead? It''s pretty convenient being able to just put and change the post icons by adding and removing files from this directory. There is also one icon called default.gif that I don''t want to list and only use it when there is no other icon chosen. I can do that myself I''m just having troubles getting all the files to show up from this directory. -- Posted via http://www.ruby-forum.com/.
> I have gif files in my public/images/posticons directory, I want to read > their filenames without the extension to list the files as a set of > radio buttons in the form: > > There is also one icon called default.gif that I don''t want to list and > only use it when there is no other icon chosen. I can do that myself I''m > just having troubles getting all the files to show up from this > directory.Nathan, Did you have any luck with this? Did you end up using the Dir and/or File classes (in the core Ruby library)? I need to do something similar but can''t find any code examples. Regards, Estelle.
Estelle Winterflood wrote:>> I have gif files in my public/images/posticons directory, I want to read >> their filenames without the extension to list the files as a set of >> radio buttons in the form: >> >> There is also one icon called default.gif that I don''t want to list and >> only use it when there is no other icon chosen. I can do that myself I''m >> just having troubles getting all the files to show up from this >> directory.Here''s what I''ve done below ("myImages" is a subdirectory of the "images/" directory of public) and it works just fine as long as you are currently in the directory that has the files or in the parent of it. I haven''t used it in my app from a view, just through the IRB console. d = Dir.entries("myImages") d.foreach do |f| filename = f.delete(f.slice(/\..../)) end That removes the ".ext" from the string and you''re left with just the filename. You could use the File I/O methods to read the attributes of the file but why bother when this works too. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
> d = Dir.entries("myImages") > d.foreach do |f| > filename = f.delete(f.slice(/\..../)) > endCorrection see below... d = Dir.entries("myImages") d.each do |f| filename = f.delete(f.slice(/\..../)) end -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---