问题
I'm running:
- rails 4.1.4
- devise 3.3
I used the RailsApp starter app to set up devise and pundit. Right now I am having trouble making a nested form attribute save. I am getting an error:
Unpermitted parameters: players
I edited the initializer file to show:
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
My models are:
class Users < ActiveRecord::Base
has_one :player
accepts_nested_attributes_for :player
end
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
class Players < ActiveRecord::Base
belongs_to :user
end
Players Controller
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
What am I doing wrong?
回答1:
I managed to get nested attributes working by following this guide..
http://kakimotonline.com/2014/03/30/extending-devise-registrations-controller/
来源:https://stackoverflow.com/questions/25734944/how-do-you-add-a-nested-attribute-to-permitted-parameters-for-devise-in-order-fo