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