0

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.com"
    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?

simonmorley
  • 2,810
  • 4
  • 30
  • 61
BC2
  • 1,129
  • 1
  • 11
  • 22

1 Answers1

2

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.com"
  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.

Rebitzele
  • 3,252
  • 1
  • 20
  • 21