Skip to content

Commit

Permalink
removed attr_accessible from all the models and instead used strong p…
Browse files Browse the repository at this point in the history
…arams.
  • Loading branch information
ifeins committed Apr 9, 2014
1 parent c74e566 commit 270378c
Show file tree
Hide file tree
Showing 15 changed files with 19 additions and 28 deletions.
7 changes: 6 additions & 1 deletion app/controllers/offices_controller.rb
Expand Up @@ -7,9 +7,14 @@ def index
end

def create
office = Office.create(params[:office])
office = Office.create(office_create_params)
respond_with office
end

private

def office_create_params
params.require(:office).permit(:name, :location_attributes => [:latitude, :longitude, :street, :city])
end

end
20 changes: 11 additions & 9 deletions app/controllers/session_controller.rb
Expand Up @@ -6,15 +6,13 @@ class SessionController < ApplicationController
before_filter :sign_in_required, :only => [:update]

def create
account = Account.find_or_create_by_provider_and_uid(
auth_hash[:provider],
auth_hash[:uid],
:user_attributes => {
:first_name => auth_hash[:info][:first_name],
:last_name => auth_hash[:info][:last_name],
:email => auth_hash[:info][:email],
:avatar_url => auth_hash[:info][:image]
}
account = Account.find_or_create_by(:provider => auth_hash[:provider], :uid => auth_hash[:uid]).update(
:user_attributes => {
:first_name => auth_hash[:info][:first_name],
:last_name => auth_hash[:info][:last_name],
:email => auth_hash[:info][:email],
:avatar_url => auth_hash[:info][:image]
}
)
user = account.user
sign_in(user)
Expand Down Expand Up @@ -43,6 +41,10 @@ def destroy

private

def user_update_params
params.require(:user).permit(:office_id, office_attributes: [:name, location_attributes: [:latitude, :longitude, :street, :city]])
end

def auth_hash
request.env['omniauth.auth']
end
Expand Down
3 changes: 2 additions & 1 deletion app/controllers/tags_controller.rb
Expand Up @@ -9,7 +9,7 @@ class TagError < StandardError; end
respond_to :json

def create
tag_definition = TagDefinition.find_by_name(params[:name])
tag_definition = TagDefinition.find_by(name: params[:name])
if tag_definition.present?
tag = restaurant.tags.build(:tag_definition => tag_definition)
tag.users << current_user
Expand Down Expand Up @@ -61,4 +61,5 @@ def load_restaurant
@restaurant = Restaurant.find(params[:restaurant_id])
end


end
1 change: 0 additions & 1 deletion app/models/account.rb
@@ -1,5 +1,4 @@
class Account < ActiveRecord::Base
belongs_to :user
attr_accessible :provider, :uid, :user_attributes
accepts_nested_attributes_for :user
end
1 change: 0 additions & 1 deletion app/models/location.rb
@@ -1,5 +1,4 @@
class Location < ActiveRecord::Base
attr_accessible :latitude, :longitude, :street, :city
acts_as_mappable default_units: :kms, lat_column_name: :latitude, lng_column_name: :longitude

def address
Expand Down
2 changes: 0 additions & 2 deletions app/models/lunch.rb
Expand Up @@ -3,8 +3,6 @@ class Lunch < ActiveRecord::Base
has_many :visits, dependent: :destroy
has_many :surveys, dependent: :destroy

attr_accessible :date

def self.today
find_by_date(Date.today)
end
Expand Down
1 change: 0 additions & 1 deletion app/models/office.rb
Expand Up @@ -2,6 +2,5 @@ class Office < ActiveRecord::Base
belongs_to :location, :dependent => :destroy
has_many :users, :dependent => :nullify

attr_accessible :name, :location_attributes
accepts_nested_attributes_for :location
end
2 changes: 0 additions & 2 deletions app/models/payment_method.rb
@@ -1,5 +1,3 @@
class PaymentMethod < ActiveRecord::Base
has_and_belongs_to_many :restaurants, :join_table => :accepted_payment_methods

attr_accessible :logo_url, :name
end
1 change: 0 additions & 1 deletion app/models/restaurant.rb
Expand Up @@ -5,7 +5,6 @@ class Restaurant < ActiveRecord::Base

mount_uploader :logo, LogoUploader

attr_accessible :name, :localized_name, :logo, :location_attributes, :tags_attributes, :payment_methods
accepts_nested_attributes_for :location
accepts_nested_attributes_for :tags
end
1 change: 0 additions & 1 deletion app/models/survey.rb
@@ -1,7 +1,6 @@
class Survey < ActiveRecord::Base
belongs_to :user
belongs_to :lunch
attr_accessible :status, :user

enum :status, [:skipped, :completed]
end
2 changes: 0 additions & 2 deletions app/models/tag.rb
Expand Up @@ -2,6 +2,4 @@ class Tag < ActiveRecord::Base
belongs_to :tag_definition
belongs_to :restaurant
has_and_belongs_to_many :users, :join_table => :users_tags

attr_accessible :quantity, :tag_definition
end
1 change: 0 additions & 1 deletion app/models/tag_definition.rb
@@ -1,3 +1,2 @@
class TagDefinition < ActiveRecord::Base
attr_accessible :name
end
1 change: 0 additions & 1 deletion app/models/user.rb
Expand Up @@ -3,7 +3,6 @@ class User < ActiveRecord::Base
has_many :votes, :dependent => :destroy
belongs_to :office

attr_accessible :avatar_url, :email, :first_name, :last_name, :account_attributes, :office_id, :office_attributes
accepts_nested_attributes_for :account
accepts_nested_attributes_for :office

Expand Down
2 changes: 0 additions & 2 deletions app/models/visit.rb
Expand Up @@ -4,6 +4,4 @@ class Visit < ActiveRecord::Base
belongs_to :restaurant

scope :for_user, ->(user) { where(user_id: user.id) }

attr_accessible :user, :restaurant
end
2 changes: 0 additions & 2 deletions app/models/vote.rb
Expand Up @@ -2,6 +2,4 @@ class Vote < ActiveRecord::Base
belongs_to :lunch
belongs_to :user
belongs_to :restaurant

attr_accessible :user, :restaurant
end

0 comments on commit 270378c

Please sign in to comment.