views:

16

answers:

1

Hi,

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 :)

+1  A: 
class ExportController < ApplicationController
  def search
    @assignment = Assignment.find_by_id(params[:assignment_id])
    @assignment.candidate_ids = params[:candidate_ids]
    @assignment.save
Eimantas
Thanks for the help!
Alex