嗨,我从下面的代码中取回了一个空值。我不知道出了什么问题。有人可以帮我吗?
class GeneratorsController < ApplicationController
before_action :set_generator, only: [:show, :edit, :update, :destroy]
# GET /generators
# GET /generators.json
def index
@generators = Generator.all
end
# GET /generators/1
# GET /generators/1.json
def show
end
# GET /generators/new
def new
@generator = Generator.new
end
# GET /generators/1/edit
def edit
end
# POST /generators
# POST /generators.json
def create
@generator = Generator.new(generator_params)
@generator.choice = params[:choice]
if params[:choice] == 'Randomly'
@generator.random_generate(params[:primer_length],params[:random_primer_generated],params[:c_primer])
#elsif params[:choice] == 'No_of_ATGC'
# @generator.no_ATGC
#elsif params[:choice] == 'Seating'
# @generator.seating
end
respond_to do |format|
if @generator.save
format.html { redirect_to @generator, notice: 'Generator was successfully created.' }
format.json { render action: 'show', status: :created, location: @generator }
else
format.html { render action: 'new' }
format.json { render json: @generator.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /generators/1
# PATCH/PUT /generators/1.json
def update
respond_to do |format|
if @generator.update(generator_params)
format.html { redirect_to @generator, notice: 'Generator was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: 'edit' }
format.json { render json: @generator.errors, status: :unprocessable_entity }
end
end
end
# DELETE /generators/1
# DELETE /generators/1.json
def destroy
@generator.destroy
respond_to do |format|
format.html { redirect_to generators_url }
format.json { head :no_content }
end
end
private
def set_generator
@generator = Generator.find(params[:id])
end
def generator_params
params.require(:generator).permit(:primer_length, :choice, :random_primer_generated)
end
end
在我的模型中
class Generator < ActiveRecord::Base
attr_accessible :choice, :primer_length, :random_primer_generated, :genome_sample
belongs_to :result
def random_generate(primer_length,random_primer_generated,c_primer)
length = primer_length
length=length.to_i
chars = 'ATGC'
seq = ''
length.times { seq << chars[rand(chars.size)] }
self.random_primer_generated = seq
c_primer =Bio::Sequence::NA.new(self.random_primer_generated.reverse)
self.c_primer=c_primer.complement.upcase
end
end
没有错误,但我得到了 random_primer_generated 和 c_primer 属性的空值