generator has_many results result belongs_to generator
when run rails console : result.find(1) , generator_id= nil. why ??? when i'm creating data , routes : localhost:3000/generator/1/results/new
it has got no error following code. how come when have in generator/index.html
<% generator.results.each |result| %> <td><%= result.ncbi_ref_seq %></td> <td><%= result.genome_sample %></td> <td><%= result.binding_times %></td> <%end%>
they're empty. whereas @generators.each |generator| gives me values of generator. in other words, result's value belonging generator empty generator values shown. want have generators , result value shown. can some1 me ?
generator.model
class generator < activerecord::base has_many :results , :dependent => :destroy attr_accessible :choice, :primer_length, :random_primer_generated, :genome_sample, :generator_id
generatorcontroller.rb
def index @generators = generator.all end def create @generator = generator.new(generator_params) @generator.choice = params[:choice] if params[:choice] == 'randomly' @generator.random_generate(generator_params) elsif params[:choice] == 'no_of_atgc' @generator.no_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] respond_to |format| if @generator.save if @generator.result_choice == 'yes' format.html { redirect_to(new_generator_result_path(@generator)) } else format.html { redirect_to @generator, notice: 'result created.' } format.json { render action: 'show', status: :created, location: @generator } end else format.html { render action: 'new' } format.json { render json: @generator.errors, status: :unprocessable_entity } end end end
result model
class result < activerecord::base attr_accessible :ncbi_ref_seq,:genome_seq, :genome_sample belongs_to :generator, foreign_key: "generator_id"
resultcontroller
def index @results = result.all end def create @result = result.new(result_params) @result.generate_result(result_params) respond_to |format| if @result.save format.html { redirect_to @result, notice: 'result created.' } format.json { render action: 'show', status: :created, location: @result } else format.html { render action: 'new' } format.json { render json: @result.errors, status: :unprocessable_entity } end end end
schema.rb
create_table "generators", force: true |t| t.integer "primer_length" t.integer "no_a" t.integer "no_t" t.integer "no_g" t.integer "no_c" t.string "choice" t.string "random_primer_generated" t.string "user_seq" t.string "c_primer" t.string "result_choice" t.datetime "created_at" t.datetime "updated_at" end create_table "results", force: true |t| t.integer "generator_id" t.string "ncbi_ref_seq" t.string "genome_seq" t.string "genome_sample" t.integer "binding_times" t.datetime "created_at" t.datetime "updated_at" end add_index "results", ["generator_id"], name: "index_results_on_generator_id" create_table "results_{:column_options=>{:null=>true}}", id: false, force: true |t| t.integer "result_id", null: false t.integer "{:column_options=>{:null=>true}}_id", null: false t.integer "generator_id" t.string "ncbi_ref_seq" t.string "genome_seq" t.string "genome_sample" t.integer "binding_times" t.datetime "created_at" t.datetime "updated_at" end add_index "results_{:column_options=>{:null=>true}}", ["generator_id"], name: "index_results_{:column_options=>{:null=>true}}_on_generator_id"
Comments
Post a Comment