Undefined local variable or `params' method for # <Result: 0x3904b18>

I have a method defined in my model

def generate_result
    self.ncbi_ref_seq=params[:ncbi_ref_seq]
    Bio::NCBI.default_email = "[email protected]"
    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 value of ncbi_ref_seq 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 why I got the error?

0
source share
1 answer

Parameters are available only to you in the controller.

However, you can pass parameters as a parameter from the controller to the model. If you used a controller action called "create":

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

and your model method might look like this:

def generate_result(params)
  self.ncbi_ref_seq=params[:ncbi_ref_seq]
  Bio::NCBI.default_email = "[email protected]"
  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 can use something more descriptive than "params", but this is a general approach.

+2

All Articles