Opps, bad copy/paste in my simplified case.  "table" or
"ranks_by_attribute" are the same hash.
On Jan 29, 8:38 pm, tom_302
<thomas.she...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> Hello,
>
> I''ve noticed a strange problem in my custom generator template.
 At
> the top of the template, I iterate through the attribute arguments to
> extract information and construct a Hash.  Later in the template, I
> loop over each_pair of the Hash.  The loop executes (I see my DEBUG
> statement) but the block between the loop never makes it from the
> template into the output file.
>
> The problem is eliminated if I don''t re-define a.name inside my
> attribute iterator.
>
> <%
>   table = Hash.new
>
>   attributes.each do |a|
>     prefix = get_assoc_prefix(a.name)  #real attribute name
>     suffix = get_assoc_suffix(a.name)  #attribute metadata
>     table[prefix] = suffix
>     a.name = prefix #THIS LINE PREVENTS THE ''if''-block
FROM BEING
> ADDED TO THE OUTPUT FILE
>   end
> %>
>
> class <%= class_name %> < ActiveRecord::Base
>   def precedence
>     sum = 0
> <% ranks_by_attribute.each_pair do |att, rank|
>     puts "DEBUG: att=#{att}, rank=#{rank}" #THIS ALWAYS PRINTS
%>
>     if self.<%= att %>
>       sum += <%= rank.to_i %>
>     end
> <% end %>
>     return sum
>   end
> end
>
> ruby 1.8.6 (2007-09-23 patchlevel 110) [i686-darwin9.1.0]
> rails 1.2.5
>
> Am I doing something wrong, or is this a bug?
>
> Thanks,
> Tom
--~--~---------~--~----~------------~-------~--~----~
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@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---