Ruby on rails Rails:属性名以整数开头的编译错误

Ruby on rails Rails:属性名以整数开头的编译错误,ruby-on-rails,compilation,integer,Ruby On Rails,Compilation,Integer,我有编译错误。你们能帮我弄一下吗。在我看来(特别是第三行的5prime_primer): 产生以下错误: 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);@outpu

我有编译错误。你们能帮我弄一下吗。在我看来(特别是第三行的5prime_primer):


产生以下错误:

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...
编译错误
/usr/home/benjamin/locus/app/views/locus_table/show.html.erb:314:no。浮动文字;把0放在点之前
…tput_buffer.append=(relation.5prime_primer)@输出缓冲区。。。。
^
/usr/home/benjamin/locus/app/views/locus_table/show.html.erb:314:语法错误,意外的tINTEGER
…put_buffer.append=(relation.5prime_primer)@输出缓冲区s。。。
^
/usr/home/benjamin/locus/app/views/locus_table/show.html.erb:315:no。浮动文字;把0放在点之前
…tput_buffer.append=(relation.3prime_primer)@输出缓冲区。。。。
^
/usr/home/benjamin/locus/app/views/locus_table/show.html.erb:315:语法错误,意外着色
…put_buffer.append=(relation.3prime_primer)@输出缓冲区s。。。
^
/usr/home/benjamin/locus/app/views/locus_table/show.html.erb:338:no。浮动文字;把0放在点之前
…tput_buffer.append=(relation.5prime_primer)@输出缓冲区。。。。
^
/usr/home/benjamin/locus/app/views/locus_table/show.html.erb:338:语法错误,意外的tINTEGER
…put_buffer.append=(relation.5prime_primer)@输出缓冲区s。。。
^
/usr/home/benjamin/locus/app/views/locus_table/show.html.erb:339:no。浮动文字;把0放在点之前
…tput_buffer.append=(relation.3prime_primer)@输出缓冲区。。。。
^
/usr/home/benjamin/locus/app/views/locus_table/show.html.erb:339:语法错误,意外的tINTEGER
…put_buffer.append=(relation.3prime_primer)@输出缓冲区s。。。
^
/usr/home/benjamin/locus/app/views/locus_table/show.html.erb:354:no。浮动文字;把0放在点之前
…tput_buffer.append=(relation.5prime_primer)@输出缓冲区。。。。
^
/usr/home/benjamin/locus/app/views/locus_table/show.html.erb:354:语法错误,意外的tINTEGER
…put_buffer.append=(relation.5prime_primer)@输出缓冲区s。。。
^
/usr/home/benjamin/locus/app/views/locus_table/show.html.erb:355:no。浮动文字;把0放在点之前
…tput_buffer.append=(relation.3prime_primer)@输出缓冲区。。。。
^
/usr/home/benjamin/locus/app/views/locus_table/show.html.erb:355:语法错误,意外着色
…put_buffer.append=(relation.3prime_primer)@输出缓冲区s。。。

你们能帮我想一想如何解决这个问题吗?

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

我在模型中定义了一个方法,然后使用hashmap查找属性:

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

和平

与大多数语言一样,ruby标识符可能不会以数字字符开头。您建议我怎么做?我没有建立这个数据库,我一直在使用它。啊,你比我快了一点:)谢谢
access_attribute '3_prime_primer', :as => 'three_prime_primer'
class AmplificationInfoTable < ActiveRecord::Base
        attr_accessor :all
        def fiveprime_primer
                attributes["5prime_primer"]
        end
end
relation.fiveprime_primer