2012-01-12 92 views
0

我有编译错误。你们能帮我找到答案吗?这在我看来,(在特定5prime_primer第三行):Rails:编译错误,以整数开头的属性名称

<tr> 
     <td><%=relation.AmpInfoName%></td> 
     <td><%=relation.5prime_primer%></td> 
     <td><%=relation.3prime_primer%></td> 
     <td><%=relation.Selective_bases_1%></td> 
     <td><%=relation.Selective_bases_2%></td> 
</tr> 

产生以下错误:

compile error 
/usr/home/benjamin/locus/app/views/locus_table/show.html.erb:314: no .<digit> floating literal anymore; put 0 before dot 
...tput_buffer.append= (relation.5prime_primer);@output_buffer.... 
          ^
/usr/home/benjamin/locus/app/views/locus_table/show.html.erb:314: syntax error, unexpected tINTEGER 
...put_buffer.append= (relation.5prime_primer);@output_buffer.s... 
          ^
/usr/home/benjamin/locus/app/views/locus_table/show.html.erb:315: no .<digit> floating literal anymore; put 0 before dot 
...tput_buffer.append= (relation.3prime_primer);@output_buffer.... 
          ^
/usr/home/benjamin/locus/app/views/locus_table/show.html.erb:315: syntax error, unexpected tINTEGER 
...put_buffer.append= (relation.3prime_primer);@output_buffer.s... 
          ^
/usr/home/benjamin/locus/app/views/locus_table/show.html.erb:338: no .<digit> floating literal anymore; put 0 before dot 
...tput_buffer.append= (relation.5prime_primer);@output_buffer.... 
          ^
/usr/home/benjamin/locus/app/views/locus_table/show.html.erb:338: syntax error, unexpected tINTEGER 
...put_buffer.append= (relation.5prime_primer);@output_buffer.s... 
          ^
/usr/home/benjamin/locus/app/views/locus_table/show.html.erb:339: no .<digit> floating literal anymore; put 0 before dot 
...tput_buffer.append= (relation.3prime_primer);@output_buffer.... 
          ^
/usr/home/benjamin/locus/app/views/locus_table/show.html.erb:339: syntax error, unexpected tINTEGER 
...put_buffer.append= (relation.3prime_primer);@output_buffer.s... 
          ^
/usr/home/benjamin/locus/app/views/locus_table/show.html.erb:354: no .<digit> floating literal anymore; put 0 before dot 
...tput_buffer.append= (relation.5prime_primer);@output_buffer.... 
          ^
/usr/home/benjamin/locus/app/views/locus_table/show.html.erb:354: syntax error, unexpected tINTEGER 
...put_buffer.append= (relation.5prime_primer);@output_buffer.s... 
          ^
/usr/home/benjamin/locus/app/views/locus_table/show.html.erb:355: no .<digit> floating literal anymore; put 0 before dot 
...tput_buffer.append= (relation.3prime_primer);@output_buffer.... 
          ^
/usr/home/benjamin/locus/app/views/locus_table/show.html.erb:355: syntax error, unexpected tINTEGER 
...put_buffer.append= (relation.3prime_primer);@output_buffer.s... 

难道你们帮我找出如何解决这个问题?

+2

与大多数语言一样,ruby标识符可能不以数字字符开头。 – 2012-01-12 20:19:21

+0

你建议我做什么?我没有建立这个数据库,我坚持使用它。 – bdeonovic 2012-01-12 20:23:30

回答

2

Ruby方法名称不能以数字开头。然而,你可以定义你自己来完成:

class Foo < ActiveRecord::Base 
    def three_prime_primer 
    read_attribute '3_prime_primer' 
    end 

    def three_prime_primer=(value) 
    write_attribute '3_prime_primer', value 
    end 
end 

它不会是很难在一个小方法来包装这件事,让你可以做

access_attribute '3_prime_primer', :as => 'three_prime_primer' 
+0

你快到了那里比我快一点:)谢谢 – bdeonovic 2012-01-12 20:58:15

0

我在模型中定义的方法,然后抬起头来使用HashMap中的属性:

class AmplificationInfoTable < ActiveRecord::Base 
     attr_accessor :all 
     def fiveprime_primer 
       attributes["5prime_primer"] 
     end 
end 

这让我做的事情,如:

relation.fiveprime_primer 

和平!