Browse Source

Allow for user object to be empty. Fixes #317.

If a flavour has only one skin, the skin selector will be omitted.  This
omits the user[setting_skin] field, and because that's the only
user[...] field on the page, the entire user object will not be present
in the request handler's params object.

This commit accounts for that scenario by avoiding params.require(:user)
and instead picking out what we need from the params hash.
closed-social-glitch-2
David Yip 6 years ago
parent
commit
6fcb870d96
No known key found for this signature in database GPG Key ID: 7DA0036508FCC0CC
1 changed files with 4 additions and 5 deletions
  1. +4
    -5
      app/controllers/settings/flavours_controller.rb

+ 4
- 5
app/controllers/settings/flavours_controller.rb View File

@ -16,7 +16,7 @@ class Settings::FlavoursController < Settings::BaseController
end end
def update def update
user_settings.update(user_settings_params(params[:flavour]).to_h)
user_settings.update(user_settings_params(params[:flavour]))
redirect_to action: 'show', flavour: params[:flavour] redirect_to action: 'show', flavour: params[:flavour]
end end
@ -27,9 +27,8 @@ class Settings::FlavoursController < Settings::BaseController
end end
def user_settings_params(flavour) def user_settings_params(flavour)
params.require(:user).merge({ setting_flavour: flavour }).permit(
:setting_flavour,
:setting_skin
)
{ setting_flavour: params.require(:flavour),
setting_skin: params.dig(:user, :setting_skin)
}.with_indifferent_access
end end
end end

Loading…
Cancel
Save