From 9ca9a6f310b5a6d5d8a6d2e98a75db0a60a0c2fb Mon Sep 17 00:00:00 2001 From: James Fleming <jflemingprod@gmail.com> Date: Tue, 9 Jul 2013 14:19:55 +0200 Subject: [PATCH] Remove duplicates and bad code habits. Remove some blank line. Do not chain bang methods. --- Gemfile | 6 +----- app/controllers/invitations_controller.rb | 5 ++++- app/controllers/profiles_controller.rb | 6 +++++- app/models/block.rb | 1 - app/models/user.rb | 3 ++- config/initializers/strong_parameters.rb | 1 + 6 files changed, 13 insertions(+), 9 deletions(-) diff --git a/Gemfile b/Gemfile index 6a1a0874c7..59087dbd4f 100644 --- a/Gemfile +++ b/Gemfile @@ -66,7 +66,7 @@ gem 'roxml', '3.1.6' gem 'ruby-oembed', '0.8.8' -#Rails 4 integration +# Please remove when migrating to Rails 4 gem 'strong_parameters' @@ -97,10 +97,6 @@ gem 'haml', '4.0.3' gem 'mobile-fu', '1.2.1' gem 'will_paginate', '3.0.4' -# Strong parameters - -gem 'strong_parameters' - ### GROUPS #### diff --git a/app/controllers/invitations_controller.rb b/app/controllers/invitations_controller.rb index 3ab954a685..4bbd21c941 100644 --- a/app/controllers/invitations_controller.rb +++ b/app/controllers/invitations_controller.rb @@ -50,7 +50,6 @@ class InvitationsController < ApplicationController end def create - inviter_params = params.require(:email_inviter).permit(:message, :locale, :emails) emails = inviter_params[:emails].split(',').map(&:strip).uniq valid_emails, invalid_emails = emails.partition { |email| valid_email?(email) } @@ -99,4 +98,8 @@ class InvitationsController < ApplicationController session[key] = nil return value end + + def inviter_params + params.require(:email_inviter).permit(:message, :locale, :emails) + end end diff --git a/app/controllers/profiles_controller.rb b/app/controllers/profiles_controller.rb index c82b1f43b3..86e50604a4 100644 --- a/app/controllers/profiles_controller.rb +++ b/app/controllers/profiles_controller.rb @@ -33,7 +33,7 @@ class ProfilesController < ApplicationController def update # upload and set new profile photo - @profile_attrs = params.require(:profile).permit(:first_name, :last_name, :gender, :bio, :location, :searchable, :tag_string, :nsfw, :date => [:year, :month, :day]) || {} + @profile_attrs = profile_params munge_tag_string @@ -78,4 +78,8 @@ class ProfilesController < ApplicationController end @profile_attrs[:tag_string] = (params[:tags]) ? params[:tags].gsub(',',' ') : "" end + + def profile_params + params.require(:profile).permit(:first_name, :last_name, :gender, :bio, :location, :searchable, :tag_string, :nsfw, :date => [:year, :month, :day]) || {} + end end diff --git a/app/models/block.rb b/app/models/block.rb index 361e4d934a..1eba8f4c8d 100644 --- a/app/models/block.rb +++ b/app/models/block.rb @@ -1,5 +1,4 @@ class Block < ActiveRecord::Base - belongs_to :person belongs_to :user diff --git a/app/models/user.rb b/app/models/user.rb index 92d9cb8e86..0ee9f6ed77 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -326,7 +326,8 @@ class User < ActiveRecord::Base params[:image_url_small] = photo.url(:thumb_small) end - params.stringify_keys!.slice!(*(Profile.column_names+['tag_string', 'date'])) + params.stringify_keys! + params.slice!(*(Profile.column_names+['tag_string', 'date'])) if self.profile.update_attributes(params) deliver_profile_update true diff --git a/config/initializers/strong_parameters.rb b/config/initializers/strong_parameters.rb index 394c1f5fd4..69fdcd47cf 100644 --- a/config/initializers/strong_parameters.rb +++ b/config/initializers/strong_parameters.rb @@ -1 +1,2 @@ +# Please remove when migrating to Rails 4 ActiveRecord::Base.send(:include, ActiveModel::ForbiddenAttributesProtection) -- GitLab