I was transforming my Rails 3 project to Rails4, but I am confused about strong parameter
.
Here is the original code in Rails 3
series_mission = SeriesMission.create({name: params[:name], mode: Mission.mode_mapping(params[:mode].to_s), start_time: start_time, end_time: end_time, gamecharacter_id: gc.id}, :without_protection => true)
It works fine. But it's wrong after I modified into this way in Rails 4
.
attrs = { name: params[:name], mode: Mission.mode_mapping(params[:mode].to_s), start_time: start_time,
end_time: end_time, gamecharacter_id: gc.id }
attrs = attrs.require(:series_mission).permit(:name, :mode, :start_time, :end_time, :gamecharacter_id)
series_mission = SeriesMission.create(attrs)
It threw this error
private method `require' called for #<Hash:0x007fd2a421e8b8>
Aucun commentaire:
Enregistrer un commentaire