你如何才能嵌套的属性添加到了设计参数允许嵌套形式工作(How do you add a nested

2019-10-30 06:05发布

我在跑:

  • 4.1.4轨道
  • 3.3设计

我用RailsApp启动应用程序设置装置和后权威人士。 现在我有麻烦的嵌套表格属性保存。 我得到一个错误:

Unpermitted parameters: players

我编辑的初始化文件显示:

def configure_permitted_parameters
  devise_parameter_sanitizer.for(:sign_up) { |u| u.permit(:first_name, :last_name, :players, :player_attributes => [:position]) }
  devise_parameter_sanitizer.for(:account_update) { |u| u.permit(:first_name, :last_name, :role, :players, :player_attributes => [:position]) }
end

我的型号有:

class Users < ActiveRecord::Base
    has_one :player

    accepts_nested_attributes_for :player
end
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
class Players < ActiveRecord::Base
    belongs_to :user
end

玩家控制器

def update
  @player = Player.find[params[:id])
  if @player.update_attributes(secure_params)
     redirect_to players_path, :notice => "Player updated"
  else
     redirect_to players_path, :alert => "Unable to update"
  end
end

private

def secure_params
  params.require(:user).permit(:user_id, :players)
end

我究竟做错了什么?

Answer 1:

我设法得到嵌套按照本指南操作工作属性..

http://kakimotonline.com/2014/03/30/extending-devise-registrations-controller/



文章来源: How do you add a nested attribute to permitted parameters for Devise in order for nested form to work