1

I'm trying to figure out why my update function won't accept nested parameters for a relation.

I've included the "accepts_nested_attributes_for :stream" in my User model.

# UsersController

# PATCH/PUT /users/me
# PATCH/PUT /users/1 
def update
  # Settings
  if params.has_key?(:settings)
    user_settings_params.each do |key,value|
      @user.settings(key.to_sym).update_attributes! value
    end
  end

  if @user.update_attributes(permitted_attributes(@user))
    render_json @user
  else
    render_json_errors @user.errors, :unprocessable_entity
  end
end
# UserPolicy

def permitted_attributes
  attributes = [
    :username,
    :email,
    :stream => [
      :title,
      :description,
      :adult,
    ]
  ]

  # attributes = attributes | [:role] if current_user.admin?
  return attributes
end

Kind regards

TemporaryName
  • 487
  • 5
  • 16

0 Answers0