2012-01-12 12 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

ほとんどの言語と同様に、ルビ識別子は数字で始まることはできません。 –

+0

私は何をお勧めしますか?私はこのデータベースを構築せず、私はそれを使用して立ち往生しています。 – bdeonovic

答えて

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

0

を行うことができるように少し方法でこれをラップするのは難しいことではないだろう、私はその後、私のモデル内のメソッドを定義し、

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

これは私のようなものを行うに許さ:

をハッシュマップを使用して属性を見上げ

平和!

関連する問題