hi rails developers @templates_array =get_templates "#{get_plugin_root}/public/converter/templates/" def get_templates(templates_path) dir = Dir.new(templates_path) templates = Array.new dir.each do |d| templates << File.basename(d.gsub(/\\/, ''/''), ''.xml'') unless (d=~/^\./) #except hidden files templates.sort! end templates end in the view page <% templateOptions = "" @templates_array.each do |i| templateOptions = templateOptions + "<option value=#{i}>#{i}</option>" end %> <%=select_tag "template", templateOptions %> I tried to use templates in selection tag but given error like: undefined method `each'' for nil:NilClass -- 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 -~----------~----~----~----~------~----~------~--~---
Quoting Ibrahim Dogru <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>: [snip]> @templates_array.each do |i| > templateOptions = templateOptions + "<option > value=#{i}>#{i}</option>" > endeach does not deal gracefully with emtpy arrays or nil. So change to if @templates_array @templates_array.each do |i| templateOptions = templateOptions + "<option value=#{i}>#{i}</option>" end end or @templates_array.each do |i| templateOptions = templateOptions + "<option value=#{i}>#{i}</option>" end if @templates_array That last line may need to be end unless @templates_array.nil? HTH, Jeffrey --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Jeffrey L. Taylor wrote:> Quoting Ibrahim Dogru <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>: > [snip] >> @templates_array.each do |i| >> templateOptions = templateOptions + "<option >> value=#{i}>#{i}</option>" >> end > > each does not deal gracefully with emtpy arrays or nil. So change to > > if @templates_array > @templates_array.each do |i| > templateOptions = templateOptions + "<option > value=#{i}>#{i}</option>" > end > end > > or > > @templates_array.each do |i| > templateOptions = templateOptions + "<option value=#{i}>#{i}</option>" > end if @templates_array > > That last line may need to be > > end unless @templates_array.nil? > > HTH, > JeffreyThank you very much for your help Jeffrey. I tried this code in another application, it worked. I don t know why here given this error. there are four files in the folder. the path is right the codes also look right however that I have error. I can not add another option and value either. -- 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 -~----------~----~----~----~------~----~------~--~---
Ibrahim Dogru wrote:> Jeffrey L. Taylor wrote: >> Quoting Ibrahim Dogru <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>: >> [snip] >>> @templates_array.each do |i| >>> templateOptions = templateOptions + "<option >>> value=#{i}>#{i}</option>" >>> end >> >> each does not deal gracefully with emtpy arrays or nil. So change to >> >> if @templates_array >> @templates_array.each do |i| >> templateOptions = templateOptions + "<option >> value=#{i}>#{i}</option>" >> end >> end >> >> or >> >> @templates_array.each do |i| >> templateOptions = templateOptions + "<option value=#{i}>#{i}</option>" >> end if @templates_array >> >> That last line may need to be >> >> end unless @templates_array.nil? >> >> HTH, >> Jeffrey > > Thank you very much for your help Jeffrey. > I tried this code in another application, it worked. I don t know why > here given this error. there are four files in the folder. the path is > right the codes also look right however that I have error. > I can not add another option and value either.OK I found the problem... I defined the @templates_array in the wrong method. that s why program could n t get array. thank you very much Jeffrey actually you can still give me idea about how to add new option and value. I still couldnt add it. when I add new option it creates 4 of them. -- 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 -~----------~----~----~----~------~----~------~--~---