Tutorial :rails - saving data to another controller



Question:

I am trying to receive data at one controller and then save it on another controller/model

From the api I wrote the following:

class ExportController < ApplicationController    def search      @assignment = Assignment.find_by_id(params[:assignment_id])      @assignment.candidates.new(params[:candidate_ids])      @assignment.candidates.create  

There is a habtm relationship between assignment and candidate.

my params look like this -

assignment_id[], candidate_ids[]

This is the error I get -

undefined method `stringify_keys!' for ["1", "3", "4", "5", "6"]:Array  

Thanks

EDIT

if I change this

 @assignment.candidates.new(params[:candidate_ids.to_i])  

I don't get a error but its creates a new candidate and then adds it to the intersection table :)


Solution:1

class ExportController < ApplicationController    def search      @assignment = Assignment.find_by_id(params[:assignment_id])      @assignment.candidate_ids = params[:candidate_ids]      @assignment.save  

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »