我在跑:
- 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
我究竟做错了什么?