开发者

rails - saving data to another controller

开发者 https://www.devze.com 2023-01-08 00:25 出处:网络
I am trying to receive data at one controller and then save it on another controller/model From the api I wrote the following:

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 b开发者_Go百科etween 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 :)


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

精彩评论

暂无评论...
验证码 换一张
取 消