可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
I read about collection_check_boxes
but I don't understand how can I set the checked values. I have the following model:
class Objective
edit view:
the html checkbox are ok but I don't know how to set the values to objective
. I was tried define objective_ids= objectives_ids
but nothing happens.
In Controller:
class ObjectivesController
EDIT The log file says Unpermitted parameters: perspective_id, objective_ids
回答1:
I solved changing the line
params.require(:objective).permit(:name, :code, :description, :objective_ids)
to
params.require(:objective).permit(:name, :code, :description, :objective_ids => [])
回答2:
I get the same problem, try this line:
params.require(:objective).permit(:name, :code, :description, :objective_ids => [])
but does not work and i change to:
params.require(:objective).permit(:name, :code, :description, {:objective_ids => []})
and it works !!