#<Result:0x3904b18>的未定义局部变量或方法`params'

编程入门 行业动态 更新时间:2024-10-11 21:29:06
本文介绍了#<Result:0x3904b18>的未定义局部变量或方法`params'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在我的模型中定义了一个方法

def generate_resultself.ncbi_ref_seq=params[:ncbi_ref_seq]Bio::NCBI.default_email = "haha@hotmail"fasta_sequence= Bio::NCBI::REST::EFetch.nucleotide(@result.ncbi_ref_seq,"fasta")fasta=Bio::FastaFormat.new(fasta_sequence)self.genome_seq = fasta.dataself.genome_sample = fasta.definition结尾

在视图中,我使用以下方法传递 ncbi_ref_seq 值:

<%= form_for(@result) do |f|%><% if @result.errors.any?%><div id="error_explanation"><h2><%=pluralize(@result.errors.count, "error") %>禁止保存此结果:</h2><ul><% @result.errors.full_messages.each do |msg|%><li><%=msg%></li><%结束%>

<%结束%><div class="field"><%= f.label :ncbi_ref_seq %><br><%= f.text_field :ncbi_ref_seq %>

<div类=按钮"><%=f.submit%>

<%结束%>

谁能告诉我为什么会出现错误?

解决方案

参数仅在控制器中对您可用.

但是,您可以将参数作为参数从控制器传递给模型.如果您使用名为创建"的控制器操作:

def 创建ClassName.generate_result(params)...结尾

您的模型方法可能如下所示:

def generate_result(params)self.ncbi_ref_seq=params[:ncbi_ref_seq]Bio::NCBI.default_email = "spykix@hotmail"fasta_sequence= Bio::NCBI::REST::EFetch.nucleotide(@result.ncbi_ref_seq,"fasta")fasta=Bio::FastaFormat.new(fasta_sequence)self.genome_seq = fasta.dataself.genome_sample = fasta.definition结尾

您可能想使用比params"更具描述性的内容,但这是通用方法.

I have a method defined in my model

def generate_result self.ncbi_ref_seq=params[:ncbi_ref_seq] Bio::NCBI.default_email = "haha@hotmail" fasta_sequence= Bio::NCBI::REST::EFetch.nucleotide(@result.ncbi_ref_seq,"fasta") fasta=Bio::FastaFormat.new(fasta_sequence) self.genome_seq = fasta.data self.genome_sample = fasta.definition end

In the view, I pass the ncbi_ref_seq value using the following method:

<%= form_for(@result) do |f| %> <% if @result.errors.any? %> <div id="error_explanation"> <h2><%= pluralize(@result.errors.count, "error") %> prohibited this result from being saved:</h2> <ul> <% @result.errors.full_messages.each do |msg| %> <li><%= msg %></li> <% end %> </ul> </div> <% end %> <div class="field"> <%= f.label :ncbi_ref_seq %><br> <%= f.text_field :ncbi_ref_seq %> </div> <div class = "button"> <%=f.submit%> </div> <% end %>

Can someone tell me how come i get the error?

解决方案

The params are only available to you in the controller.

However, you can pass the params as a parameter from the controller to the model. If you were using a controller action called 'create':

def create ClassName.generate_result(params) ... end

and your model method could look like this:

def generate_result(params) self.ncbi_ref_seq=params[:ncbi_ref_seq] Bio::NCBI.default_email = "spykix@hotmail" fasta_sequence= Bio::NCBI::REST::EFetch.nucleotide(@result.ncbi_ref_seq,"fasta") fasta=Bio::FastaFormat.new(fasta_sequence) self.genome_seq = fasta.data self.genome_sample = fasta.definition end

You may want to use something more descriptive than 'params', but this is the general approach.

更多推荐

#&lt;Result:0x3904b18&gt;的未定义局部变量或方法`params'

本文发布于:2023-10-27 23:41:39,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1534871.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:变量   局部   未定义   方法   Result

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!