不调用模型方法

时间:2013-12-09 12:29:48

标签: ruby-on-rails ruby-on-rails-4

我有一个属于Generator.rb的方法

生成器控制器

  # GET /generators/new
  def new
    @generator = current_user.generators.build(params[:generator])
  end

  # POST /generators
  # POST /generators.json
  def create    
    @generator = current_user.generators.build(params[:generator])
    @generator.user_id = current_user.id if current_user
    @generator.choice = params[:choice]
      if params[:choice] == 'Randomly'
          @generator.random_generate(generator_params)
      elsif params[:choice] == 'Specified ATGC'
          @generator.specified_ATGC(params[:no_A],params[:no_T],params[:no_G],params[:no_C])
      elsif params[:choice] == 'Seating'
          @generator.seating(params[:user_seq])
      end

    @generator.result_choice=params[:result_choice]
    @generator.save
    respond_to do |format|
       if @generator.result_choice == 'Yes'
              format.html { redirect_to(user_generator_path(:user_id => current_user.id, :id => generator.id)) }
       else
              format.html { redirect_to(user_generators_path(@generator) ) }
       end
     end 
  end

但是当我运行rails console,Generator.all时,只有user_id和generator_id存在。但是Generator变量都是零。我怎么解决这个问题?我的Generator控制器是否有问题?我不知道如何将User链接到我的Generator。此外,Generator还将与Result链接。

User.rb

class User < ActiveRecord::Base
  has_many :generators
  has_many :results, :through=>:generators

Generator.rb

class Generator < ActiveRecord::Base
  has_one :result , :dependent => :destroy
  belongs_to :user
  attr_accessible :choice, :primer_length, :random_primer_generated, :generator_id

Result.rb

class Result < ActiveRecord::Base
   attr_accessible :generator_id,:ncbi_ref_seq,:genome_seq, :genome_sample
   belongs_to :generator

0 个答案:

没有答案