未定义的方法`save'为0:Fixnum

时间:2013-12-15 14:04:27

标签: ruby-on-rails

我有一个结果和一个发电机。生成器has_one结果。结果属于生成器。在我的协会中,我做了类似的事情:

结果表单(我在Generator SHOW.HTML

中呈现此结果表单
<%= form_for([@generator,@generator.build_result(params[:result])]) do |f|%>
<script>
$(document).ready(function(){
        $("#accession_number").click(function(){
            $("#FASTA").hide();
            $("#highlight").hide();
        })
        $("#FASTA").click(function(){
            $("#accession_number").hide();
            $("#highlight").hide();
        })    
        $("#reset").click(function(){
            $("#accession_number").show();
            $("#FASTA").show();
            $("#highlight").show();
        })
});
</script>

  <font size ="6">*** <u>Choose ONE of the input methods</u> *** </font>
  <p id="accession_number">
    <label><strong><font size ="3">NCBI accession number:</font></strong></label><br />
  <%= f.text_field(:ncbi_ref_seq,placeholder: 'Accession Number')%>
  </p>

  <p id="highlight"><font size ="5">
        OR  
  </font></p>

  <p id="FASTA">
    <strong><font size ="3">Paste your sequence here: ( FASTA format ) :</font></strong> 
    <%= f.text_area(:genome_seq,size: "50x10",placeholder: 'Input your sequence here')%>
 </p>

  <input type="reset" value="Reset" id="reset">
    <%= f.submit 'Analyze' %>
<% end %>

结果控制器

def new
    @result=Result.new
  end

  # POST /results :url=> generator_results_path(@generator)
  # POST /results.json TGATGAACATCATGATGAGGTGATGACATCACATCATTGACTGATGCATCATGATG
  def create    
    @generator = Generator.find(params[:generator_id])
    @result = @generator.build_result(params[:result])
    @generator =@result.generate_result(result_params)
    @generator=@generator.save
    redirect_to generators_path
  end

但是,在提交表单后,我收到错误:

  

保存未定义

我可以知道为什么吗?我该如何解决它们呢?

结果模型

 def generate_result(result_params) 
       if ncbi_ref_seq == ''
         fasta = Bio::FastaFormat.new(self.genome_seq)
         self.genome_sample = fasta.definition
         self.ncbi_ref_seq = fasta.accession 
       else
              ref_seq = self.ncbi_ref_seq
              Bio::NCBI.default_email = "spykix@hotmail.com"
              fasta_sequence = Bio::NCBI::REST::EFetch.nucleotide(ref_seq,"fasta")
              fasta=Bio::FastaFormat.new(fasta_sequence)
              self.genome_seq = fasta.data
              self.genome_sample = fasta.definition  
       end 
    self.get_binding_t(genome_seq)   
          #in the end of this function, delete genome_seq      
    end

   def get_binding_t(genome_seq)
        ge=self.generator_id
        g=Generator.find(ge)
        primer_length=g.primer_length
        forward=self.genome_seq.scan(g.f_primer) #pass forward and reverse count for next function determine
        reverse=self.genome_seq.scan(g.r_primer)
        self.binding_times= forward.length() + reverse.length() 

        if self.binding_times <2 || reverse.length == 0 || forward.length == 0
            self.amp_frags=0 
        else        
            xf=self.genome_seq.gsub(g.f_primer,' F ') 
            xfr=xf.gsub(g.r_primer,' R ')

            self.findstarter(xfr,primer_length)
        end 
   end

   def findstarter(xfr,primer_length)
        list=xfr.scan(/\w+/)  
        f_index=list.index('F') 
        r_index=list.index('R') 

        if f_index<r_index==true
          startpos=f_index
        else
          startpos=r_index
        end        

    self.est_amp_frags(startpos,primer_length,*list)   
   end

   def est_amp_frags(startpos,primer_length,*list)  
      frags = 0
      list_size= list.length
      while startpos<list_size-2 do  
        checker=startpos+2
        tot_len=0   
        if list[startpos]=='F'
                while checker<list.length do  
                    if list[checker] == 'R' 
                        if list[checker-1] =='R' || list[checker-1] =='F'
                          tot_len+=primer_length
                        else 
                          tot_len+=list[checker-1].length
                        end

                        if tot_len >2 && tot_len<31 # 200-2000
                            frags +=1 
                            self.amp_frags=frags
                            get_seq_pos(startpos,primer_length,tot_len,*list)
                        end  
                        checker+=1
                    else
                        if list[checker-1] =='F' || list[checker-1]=='R'
                          tot_len+=primer_length
                        else  
                        tot_len+=list[checker-1].length
                        end
                    checker+=1
                    end
                end
        startpos+=1      
        elsif list[startpos]=='R'
              while checker<list.length do              
                    if list[checker] == 'F' 
                        if list[checker-1] =='F' || list[checker-1] =='R'
                          tot_len+=primer_length
                        else 
                          tot_len+=list[checker-1].length
                        end

                        if tot_len >2 && tot_len<31 #200-2000 REMEMBER TO CHANGE !!
                            frags +=1 
                            self.amp_frags=frags
                            get_seq_pos(startpos,primer_length,tot_len,*list)
                        end  
                    checker+=1
                    else
                        if list[checker-1] =='R' || list[checker-1]=='F'
                            tot_len+=primer_length
                        else  
                          tot_len+=list[checker-1].length
                        end
                    checker+=1
                    end
              end
        startpos+=1        
        else
            startpos+=1       
        end
      end   #while end        
   end

   def get_seq_pos(startpos,primer_length,tot_len,*list)#primer.length
      seq_pos1 =0
      seq_pos2= 0
          if startpos==0
            seq_pos1 = primer_length
            seq_pos2 = seq_pos1 + tot_len     
          else 
              while startpos!=-1 do
                    if list[startpos] == 'R' || list[startpos] == 'F'
                      seq_pos1 += primer_length
                    else
                      seq_pos1 += list[startpos].length
                    end
              seq_pos2 = seq_pos1+tot_len
              startpos-=1
              end    
          end #ADD IN DATA ATTRIBUTES POS1 & POS2
          self.seqpos1=seqpos1.to_a.push seq_pos1
          self.seqpos2=seqpos2.to_a.push seq_pos2
          self.genome_seq = nil
   end

Result_params

def result_params
      params.require(:result).permit(:ncbi_ref_seq,:genome_seq,:genome_sample,:binding_times,:amp_frags,:seqpos1,:seqpos2)
    end

0 个答案:

没有答案