-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathresult.txt
6303 lines (5277 loc) · 180 KB
/
result.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
app/controllers/application_controller.rb
---
class ApplicationController < ActionController::Base
protect_from_forgery
def get_ratings!
@ratings = current_user.ratings
@ratings_movie_ids = @ratings.pluck(:movie_id)
@rating_values = {}
current_user.ratings.each do |rating|
@rating_values[rating.movie_id] = rating.rating_value
end
end
end
app/controllers/home_controller.rb
---
class HomeController < ApplicationController
def index
redirect_to recommendations_path if current_user
end
end
app/controllers/ratings_controller.rb
---
class RatingsController < ApplicationController
before_filter :authenticate_user!
before_filter :get_ratings!
def index
@movies = Movie.where(demo_display: true).sample(24)
end
def create
rating = current_user.ratings.build(rating_params)
if rating.save
UpdateRecommendationsWorker.perform_async(rating.id)
render json: rating
else
render json: rating.errors
end
end
def update
rating = current_user.ratings.find(params[:id])
rating.rating_value = params[:rating_value]
if rating.save
UpdateRecommendationsWorker.perform_async(rating.id)
render json: rating
else
flash[:notice] = "Your rating was not updated."
render json: rating.errors
end
end
def search
result = Pose.search(params[:query], [Movie, Actor, Director], limit: 20)
query_match = params[:query].downcase
result[Actor].each do |actor|
if actor.name.downcase == query_match
@actor_movies = actor.movies
end
end
result[Director].each do |director|
if director.name.downcase == query_match
@director_movies = director.movies
end
end
@movies = result[Movie]
end
private
def rating_params
{ movie_id: params[:movie_id].to_i,
rating_value: params[:rating_value].to_i }
end
end
app/controllers/recommendations_controller.rb
---
class RecommendationsController < ApplicationController
before_filter :authenticate_user!
before_filter :get_ratings!
def index
@recommendations = current_user.unrated_recommendations
.includes(:movie)
.shuffle
end
end
app/controllers/users_controller.rb
---
class UsersController < ApplicationController
before_filter :authenticate_user!
before_filter :get_ratings!
def ratings
@ratings = current_user.ratings.reverse
end
end
app/helpers/application_helper.rb
---
module ApplicationHelper
def resource_name
:user
end
def resource
@resource ||= User.new
end
def devise_mapping
@devise_mapping ||= Devise.mappings[:user]
end
end
app/models/actor.rb
---
class Actor < ActiveRecord::Base
has_many :actors_movies, dependent: :destroy
has_many :movies, through: :actors_movies
validates :name, presence: true
posify { name }
end
app/models/actors_movie.rb
---
class ActorsMovie < ActiveRecord::Base
belongs_to :actor
belongs_to :movie
end
app/models/director.rb
---
class Director < ActiveRecord::Base
has_many :directors_movies, dependent: :destroy
has_many :movies, through: :directors_movies
validates :name, presence: true
posify { name }
end
app/models/directors_movie.rb
---
class DirectorsMovie < ActiveRecord::Base
belongs_to :movie
belongs_to :director
end
app/models/genre.rb
---
class Genre < ActiveRecord::Base
has_many :genres_movies, dependent: :destroy
has_many :movies, through: :genres_movies
validates :name, presence: true
end
app/models/genres_movie.rb
---
class GenresMovie < ActiveRecord::Base
belongs_to :movie
belongs_to :genre
end
app/models/movie.rb
---
class Movie < ActiveRecord::Base
has_many :ratings, dependent: :destroy
has_many :users, through: :ratings
has_many :actors_movies, dependent: :destroy
has_many :actors, through: :actors_movies
has_many :genres_movies, dependent: :destroy
has_many :genres, through: :genres_movies
has_many :directors_movies, dependent: :destroy
has_many :directors, through: :directors_movies
has_many :recommendations, dependent: :destroy
has_many :users, through: :recommendations
posify { title }
end
app/models/rating.rb
---
class Rating < ActiveRecord::Base
belongs_to :movie
belongs_to :user
validates_uniqueness_of :user_id, scope: :movie_id
validates :movie_id, :user_id, :rating_value, presence: true
validates :rating_value, numericality: {
greater_than_or_equal_to: 1, less_than_or_equal_to: 5
}
attr_accessible :movie_id, :rating_value
end
app/models/recommendation.rb
---
class Recommendation < ActiveRecord::Base
belongs_to :user
belongs_to :movie
validates_uniqueness_of :user_id, scope: :movie_id
validates :user_id, :movie_id, presence: true
end
app/models/user.rb
---
class User < ActiveRecord::Base
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
attr_accessible :password_confirmation, :name, :email, :password
has_many :ratings, dependent: :destroy
has_many :movies, through: :ratings
has_many :recommendations, dependent: :destroy
has_many :movies, through: :recommendations
def unrated_recommendations
recommendations.where.not(movie_id: ratings.pluck(:movie_id))
end
# Find the user's closest user using PearsonCorrelation
def closest_user
users = User.includes(ratings: :movie)
result = [users.first.id, pearson_correlation(users.first)]
users.each do |user|
next if user.id == self.id
current_pearson_correlation = pearson_correlation(user)
if (1 - current_pearson_correlation).abs < (1 - result.last).abs
result = [user, current_pearson_correlation]
end
end
result[1] == 0 ? nil : result[0]
end
def movie_rating_pairs
ratings.pluck(:movie_id, :rating_value).to_h
end
private
def pearson_correlation(other_user)
PearsonCorrelation.new(self, other_user).calculate
end
end
app/services/pearson_correlation.rb
---
# Calculates the distance between two users. The pearson correlation coefficient
class PearsonCorrelation
attr_reader :user_ratings, :user_rating_average,
:other_user_ratings, :other_user_rating_average
def initialize(user, other_user)
@user_ratings = user.movie_rating_pairs
@other_user_ratings = other_user.movie_rating_pairs
@user_rating_average = rating_average(user_ratings)
@other_user_rating_average = rating_average(other_user_ratings)
end
def calculate
return 0 if shared_movie_ids.empty?
deviation / denominator
end
private
def denominator
Math.sqrt(square_of_user_ratings * square_of_other_user_ratings).to_f
end
def deviation
shared_movie_ids.inject(0) do |sum, movie_id|
target = user_ratings[movie_id] - user_rating_average
other = other_user_ratings[movie_id] - other_user_rating_average
sum + (target * other)
end.to_f
end
def rating_average(ratings)
user_rating_sum = ratings.values.sum
return 0 if shared_movie_ids.size.zero?
user_rating_sum / shared_movie_ids.size
end
def shared_movie_ids
@shared_movie_ids ||= user_ratings.keys & other_user_ratings.keys
end
def square_of(ratings, average)
shared_movie_ids.inject(0) do |sum, movie_id|
sum + ((ratings[movie_id] - average) ** 2)
end
end
def square_of_user_ratings
square_of(user_ratings, user_rating_average)
end
def square_of_other_user_ratings
square_of(other_user_ratings, other_user_rating_average)
end
end
app/services/recommendation_system.rb
---
class RecommendationSystem
attr_reader :current_user, :rated_movie, :rating_value, :already_rated_ids
def initialize(rating)
@current_user = rating.user
@rating_value = rating.rating_value.to_i
@rated_movie = Movie.find(rating.movie_id)
@already_rated_ids = @current_user.ratings.pluck(:movie_id)
end
def update_recommendations
return if rating_value < 3
recommendations_from_closest_user = []
if closest_user
movies_to_rec = movies_from_closest_user
recommendations_from_closest_user = create_recommendations(movies_to_rec)
end
newly_rated_movie_cluster = unit_cluster(recommendations_from_closest_user)
# TODO: Hacer que esto sea el mismo metodo que create_recommendations.
#
# Hacer que create_recommendations tome otro parametro, que va a ser
# si la recomendacion es colaborativa o por contenido, que va a vivir en una
# columna nueva bajo la tabla de recomendaciones.
#
# Hacer que la recomendacion tenga otra columna nueva que va a ser un dato,
# el mail de la persona con la cual tenes el gusto en comun, si la rec fuese
# colaborativa, o la pelicula que origino la recomendacion si la rec es por
# contenido.
newly_rated_movie_cluster.each do |new_movie|
current_user.recommendations.create(movie_id: new_movie)
end
end
def create_recommendations(movie_ids)
movie_ids = movie_ids[0..collaborative_limit]
movie_ids.each { |id| current_user.recommendations.create(movie_id: id) }
end
def unit_cluster(total_recs = [])
directors = rated_movie.directors
actors = rated_movie.actors
genres = rated_movie.genres
directors_movies = entity_recommendation_list(directors, Director)
actors_movies = entity_recommendation_list(actors, Actor)
genres_movies = entity_recommendation_list(genres, Genre)
actor_director_genre_recs = directors_movies & actors_movies & genres_movies
actor_director_recs = directors_movies & actors_movies
director_genre_recs = directors_movies & genres_movies
actor_genre_recs = genres_movies & actors_movies
populate_recommendation_list(actor_director_genre_recs, total_recs)
populate_recommendation_list(actor_director_recs, total_recs)
populate_recommendation_list(director_genre_recs, total_recs)
populate_recommendation_list(actor_genre_recs, total_recs)
populate_recommendation_list(directors_movies, total_recs)
populate_recommendation_list(actors_movies, total_recs)
populate_recommendation_list(genres_movies, total_recs)
total_recs.uniq
end
# Adds movies from clustering to recommendation list
# (there is a limit to the amount of movies added based on rating value
# of the target movie)
def populate_recommendation_list(chosen_list, total_recs)
return if recommendation_limit_reached?(total_recs)
chosen_list.each do |movie_id|
break if recommendation_limit_reached?(total_recs)
next if movie_id == rated_movie.id
total_recs << movie_id unless already_rated_ids.include? movie_id
end
end
private
def collaborative_limit
RECOMMENDATION_LIMITS[rating_value] * 0.6
end
def entity_recommendation_list(entities, klass)
entities.map do |entity|
klass.where(id: entity.id).includes(:movies).first.movies.pluck(:id)
end.flatten
end
def movies_from_closest_user
closest_user.ratings
.where("ratings.rating_value >= 3")
.where("ratings.movie_id not in (?)", already_rated_ids)
.pluck(:movie_id)
end
def recommendation_limit_reached?(total_recs)
total_recs.length >= RECOMMENDATION_LIMITS[rating_value]
end
def closest_user
@closest_user ||= current_user.closest_user
end
end
app/workers/update_recommendations_worker.rb
---
class UpdateRecommendationsWorker
include Sidekiq::Worker
def perform(rating_id)
rating = Rating.where(id: rating_id).first
RecommendationSystem.new(rating).update_recommendations
end
end
config/application.rb
---
require File.expand_path('../boot', __FILE__)
require "rails/all"
Bundler.require(*Rails.groups)
module MovieRecommendations
class Application < Rails::Application
# Settings in config/environments/* take precedence over those specified here.
# Application configuration should go into files in config/initializers
# -- all .rb files in that directory are automatically loaded.
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
# config.time_zone = 'Central Time (US & Canada)'
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
# config.i18n.default_locale = :de
# Configure the default encoding used in templates for Ruby 1.9.
config.encoding = "utf-8"
# Configure sensitive parameters which will be filtered from the log file.
config.filter_parameters += [:password, :password_confirmation]
# Enable escaping HTML in JSON.
config.active_support.escape_html_entities_in_json = true
# Enable the asset pipeline
config.assets.enabled = true
# Version of your assets, change this if you want to expire all your assets
config.assets.version = '1.0'
end
end
config/boot.rb
---
require 'rubygems'
# Set up gems listed in the Gemfile.
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
config/environment.rb
---
# Load the rails application
require File.expand_path('../application', __FILE__)
# Initialize the rails application
MovieRecommendations::Application.initialize!
config/environments/development.rb
---
MovieRecommendations::Application.configure do
# Settings specified here will take precedence over those in config/application.rb
# In the development environment your application's code is reloaded on
# every request. This slows down response time but is perfect for development
# since you don't have to restart the web server when you make code changes.
config.cache_classes = false
config.eager_load = false
# Show full error reports and disable caching
config.consider_all_requests_local = true
config.action_controller.perform_caching = false
# ActionMailer Config
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
config.action_mailer.delivery_method = :smtp
# change to true to allow email to be sent during development
config.action_mailer.perform_deliveries = false
config.action_mailer.raise_delivery_errors = true
config.action_mailer.default charset: "utf-8"
# Print deprecation notices to the Rails logger
config.active_support.deprecation = :log
# Only use best-standards-support built into browsers
config.action_dispatch.best_standards_support = :builtin
# Do not compress assets
config.assets.compress = false
# Expands the lines which load the assets
config.assets.debug = true
config.action_mailer.smtp_settings = {
address: "smtp.gmail.com",
port: 587,
domain: ENV["DOMAIN_NAME"],
authentication: "plain",
enable_starttls_auto: true,
user_name: ENV["GMAIL_USERNAME"],
password: ENV["GMAIL_PASSWORD"]
}
end
config/environments/production.rb
---
MovieRecommendations::Application.configure do
# Settings specified here will take precedence over those in config/application.rb
# Code is not reloaded between requests
config.cache_classes = true
config.eager_load = false
# Full error reports are disabled and caching is turned on
config.consider_all_requests_local = false
config.action_controller.perform_caching = true
# Disable Rails's static asset server (Apache or nginx will already do this)
config.serve_static_assets = false
# Compress JavaScripts and CSS
config.assets.compress = true
# Don't fallback to assets pipeline if a precompiled asset is missed
config.assets.compile = false
# Generate digests for assets URLs
config.assets.digest = true
# Defaults to nil and saved in location specified by config.assets.prefix
# config.assets.manifest = YOUR_PATH
# Specifies the header that your server uses for sending files
# config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache
# config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx
# Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
# config.force_ssl = true
# See everything in the log (default is :info)
# config.log_level = :debug
# Prepend all log lines with the following tags
# config.log_tags = [ :subdomain, :uuid ]
# Use a different logger for distributed setups
# config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new)
# Use a different cache store in production
# config.cache_store = :mem_cache_store
# Enable serving of images, stylesheets, and JavaScripts from an asset server
# config.action_controller.asset_host = "http://assets.example.com"
# Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added)
# config.assets.precompile += %w( search.js )
# Disable delivery errors, bad email addresses will be ignored
# config.action_mailer.raise_delivery_errors = false
# Enable threaded mode
# config.threadsafe!
# Enable locale fallbacks for I18n (makes lookups for any locale fall back to
# the I18n.default_locale when a translation can not be found)
config.i18n.fallbacks = true
# Send deprecation notices to registered listeners
config.active_support.deprecation = :notify
config.action_mailer.smtp_settings = {
address: "smtp.gmail.com",
port: 587,
domain: ENV["DOMAIN_NAME"],
authentication: "plain",
enable_starttls_auto: true,
user_name: ENV["GMAIL_USERNAME"],
password: ENV["GMAIL_PASSWORD"]
}
config.action_mailer.default_url_options = { :host => 'example.com' }
config.action_mailer.delivery_method = :smtp
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = false
config.action_mailer.default charset: "utf-8"
end
config/environments/test.rb
---
MovieRecommendations::Application.configure do
# Settings specified here will take precedence over those in config/application.rb
# The test environment is used exclusively to run your application's
# test suite. You never need to work with it otherwise. Remember that
# your test database is "scratch space" for the test suite and is wiped
# and recreated between test runs. Don't rely on the data there!
config.cache_classes = true
config.eager_load = false
# Configure static asset server for tests with Cache-Control for performance
config.serve_static_files = true
config.static_cache_control = "public, max-age=3600"
# Show full error reports and disable caching
config.consider_all_requests_local = true
config.action_controller.perform_caching = false
# Raise exceptions instead of rendering exception templates
config.action_dispatch.show_exceptions = false
# Disable request forgery protection in test environment
config.action_controller.allow_forgery_protection = false
# Tell Action Mailer not to deliver emails to the real world.
# The :test delivery method accumulates sent emails in the
# ActionMailer::Base.deliveries array.
config.action_mailer.delivery_method = :test
# Print deprecation notices to the stderr
config.active_support.deprecation = :stderr
# ActionMailer Config
config.action_mailer.default_url_options = { :host => 'example.com' }
end
config/initializers/backtrace_silencers.rb
---
# Be sure to restart your server when you modify this file.
# You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
# Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }
# You can also remove all the silencers if you're trying to debug a problem that might stem from framework code.
# Rails.backtrace_cleaner.remove_silencers!
config/initializers/constants.rb
---
RECOMMENDATION_LIMITS = { 3 => 10, 4 => 20, 5 => 30 }
config/initializers/devise.rb
---
# Use this hook to configure devise mailer, warden hooks and so forth.
# Many of these configuration options can be set straight in your model.
Devise.setup do |config|
# ==> Mailer Configuration
# Configure the e-mail address which will be shown in Devise::Mailer,
# note that it will be overwritten if you use your own mailer class with default "from" parameter.
config.mailer_sender = "[email protected]"
# Configure the class responsible to send e-mails.
# config.mailer = "Devise::Mailer"
# ==> ORM configuration
# Load and configure the ORM. Supports :active_record (default) and
# :mongoid (bson_ext recommended) by default. Other ORMs may be
# available as additional gems.
require 'devise/orm/active_record'
# ==> Configuration for any authentication mechanism
# Configure which keys are used when authenticating a user. The default is
# just :email. You can configure it to use [:username, :subdomain], so for
# authenticating a user, both parameters are required. Remember that those
# parameters are used only when authenticating and not when retrieving from
# session. If you need permissions, you should implement that in a before filter.
# You can also supply a hash where the value is a boolean determining whether
# or not authentication should be aborted when the value is not present.
# config.authentication_keys = [ :email ]
# Configure parameters from the request object used for authentication. Each entry
# given should be a request method and it will automatically be passed to the
# find_for_authentication method and considered in your model lookup. For instance,
# if you set :request_keys to [:subdomain], :subdomain will be used on authentication.
# The same considerations mentioned for authentication_keys also apply to request_keys.
# config.request_keys = []
# Configure which authentication keys should be case-insensitive.
# These keys will be downcased upon creating or modifying a user and when used
# to authenticate or find a user. Default is :email.
config.case_insensitive_keys = [ :email ]
# Configure which authentication keys should have whitespace stripped.
# These keys will have whitespace before and after removed upon creating or
# modifying a user and when used to authenticate or find a user. Default is :email.
config.strip_whitespace_keys = [ :email ]
# Tell if authentication through request.params is enabled. True by default.
# It can be set to an array that will enable params authentication only for the
# given strategies, for example, `config.params_authenticatable = [:database]` will
# enable it only for database (email + password) authentication.
# config.params_authenticatable = true
# Tell if authentication through HTTP Auth is enabled. False by default.
# It can be set to an array that will enable http authentication only for the
# given strategies, for example, `config.http_authenticatable = [:token]` will
# enable it only for token authentication. The supported strategies are:
# :database = Support basic authentication with authentication key + password
# :token = Support basic authentication with token authentication key
# :token_options = Support token authentication with options as defined in
# http://api.rubyonrails.org/classes/ActionController/HttpAuthentication/Token.html
# config.http_authenticatable = false
# If http headers should be returned for AJAX requests. True by default.
# config.http_authenticatable_on_xhr = true
# The realm used in Http Basic Authentication. "Application" by default.
# config.http_authentication_realm = "Application"
# It will change confirmation, password recovery and other workflows
# to behave the same regardless if the e-mail provided was right or wrong.
# Does not affect registerable.
# config.paranoid = true
# By default Devise will store the user in session. You can skip storage for
# :http_auth and :token_auth by adding those symbols to the array below.
# Notice that if you are skipping storage for all authentication paths, you
# may want to disable generating routes to Devise's sessions controller by
# passing :skip => :sessions to `devise_for` in your config/routes.rb
config.skip_session_storage = [:http_auth]
# ==> Configuration for :database_authenticatable
# For bcrypt, this is the cost for hashing the password and defaults to 10. If
# using other encryptors, it sets how many times you want the password re-encrypted.
#
# Limiting the stretches to just one in testing will increase the performance of
# your test suite dramatically. However, it is STRONGLY RECOMMENDED to not use
# a value less than 10 in other environments.
config.stretches = Rails.env.test? ? 1 : 10
# Setup a pepper to generate the encrypted password.
# config.pepper = "ab768c223c2f0ca947058ae1c221d87dec901b796f65a38b9de60540aa626fea431a11dda19223eb5944696613a3699eecf223e05fd8a084aac452d5827a4bf1"
# ==> Configuration for :confirmable
# A period that the user is allowed to access the website even without
# confirming his account. For instance, if set to 2.days, the user will be
# able to access the website for two days without confirming his account,
# access will be blocked just in the third day. Default is 0.days, meaning
# the user cannot access the website without confirming his account.
# config.allow_unconfirmed_access_for = 2.days
# A period that the user is allowed to confirm their account before their
# token becomes invalid. For example, if set to 3.days, the user can confirm
# their account within 3 days after the mail was sent, but on the fourth day
# their account can't be confirmed with the token any more.
# Default is nil, meaning there is no restriction on how long a user can take
# before confirming their account.
# config.confirm_within = 3.days
# If true, requires any email changes to be confirmed (exactly the same way as
# initial account confirmation) to be applied. Requires additional unconfirmed_email
# db field (see migrations). Until confirmed new email is stored in
# unconfirmed email column, and copied to email column on successful confirmation.
config.reconfirmable = true
# Defines which key will be used when confirming an account
# config.confirmation_keys = [ :email ]
# ==> Configuration for :rememberable
# The time the user will be remembered without asking for credentials again.
# config.remember_for = 2.weeks
# If true, extends the user's remember period when remembered via cookie.
# config.extend_remember_period = false
# Options to be passed to the created cookie. For instance, you can set
# :secure => true in order to force SSL only cookies.
# config.rememberable_options = {}
# ==> Configuration for :validatable
# Range for password length. Default is 8..128.
config.password_length = 8..128
# Email regex used to validate email formats. It simply asserts that
# one (and only one) @ exists in the given string. This is mainly
# to give user feedback and not to assert the e-mail validity.
# config.email_regexp = /\A[^@]+@[^@]+\z/
# ==> Configuration for :timeoutable
# The time you want to timeout the user session without activity. After this
# time the user will be asked for credentials again. Default is 30 minutes.
# config.timeout_in = 30.minutes
# If true, expires auth token on session timeout.
# config.expire_auth_token_on_timeout = false
# ==> Configuration for :lockable
# Defines which strategy will be used to lock an account.
# :failed_attempts = Locks an account after a number of failed attempts to sign in.
# :none = No lock strategy. You should handle locking by yourself.
# config.lock_strategy = :failed_attempts
# Defines which key will be used when locking and unlocking an account
# config.unlock_keys = [ :email ]
# Defines which strategy will be used to unlock an account.
# :email = Sends an unlock link to the user email
# :time = Re-enables login after a certain amount of time (see :unlock_in below)
# :both = Enables both strategies
# :none = No unlock strategy. You should handle unlocking by yourself.
# config.unlock_strategy = :both
# Number of authentication tries before locking an account if lock_strategy
# is failed attempts.
# config.maximum_attempts = 20
# Time interval to unlock the account if :time is enabled as unlock_strategy.
# config.unlock_in = 1.hour
# ==> Configuration for :recoverable
#
# Defines which key will be used when recovering the password for an account
# config.reset_password_keys = [ :email ]
# Time interval you can reset your password with a reset password key.
# Don't put a too small interval or your users won't have the time to
# change their passwords.
config.reset_password_within = 6.hours
# ==> Configuration for :encryptable
# Allow you to use another encryption algorithm besides bcrypt (default). You can use
# :sha1, :sha512 or encryptors from others authentication tools as :clearance_sha1,
# :authlogic_sha512 (then you should set stretches above to 20 for default behavior)
# and :restful_authentication_sha1 (then you should set stretches to 10, and copy
# REST_AUTH_SITE_KEY to pepper).
#
# Require the `devise-encryptable` gem when using anything other than bcrypt
# config.encryptor = :sha512
# ==> Configuration for :token_authenticatable
# Defines name of the authentication token params key
# config.token_authentication_key = :auth_token
# ==> Scopes configuration
# Turn scoped views on. Before rendering "sessions/new", it will first check for
# "users/sessions/new". It's turned off by default because it's slower if you
# are using only default views.
# config.scoped_views = false
# Configure the default scope given to Warden. By default it's the first
# devise role declared in your routes (usually :user).
# config.default_scope = :user
# Set this configuration to false if you want /users/sign_out to sign out
# only the current scope. By default, Devise signs out all scopes.
# config.sign_out_all_scopes = true
# ==> Navigation configuration
# Lists the formats that should be treated as navigational. Formats like
# :html, should redirect to the sign in page when the user does not have
# access, but formats like :xml or :json, should return 401.
#
# If you have any extra navigational formats, like :iphone or :mobile, you
# should add them to the navigational formats lists.
#
# The "*/*" below is required to match Internet Explorer requests.
# config.navigational_formats = ["*/*", :html]
# The default HTTP method used to sign out a resource. Default is :delete.
config.sign_out_via = Rails.env.test? ? :get : :delete
# ==> OmniAuth
# Add a new OmniAuth provider. Check the wiki for more information on setting
# up on your models and hooks.
# config.omniauth :github, 'APP_ID', 'APP_SECRET', :scope => 'user,public_repo'
# ==> Warden configuration
# If you want to use other strategies, that are not supported by Devise, or
# change the failure app, you can configure them inside the config.warden block.
#
# config.warden do |manager|
# manager.intercept_401 = false
# manager.default_strategies(:scope => :user).unshift :some_external_strategy
# end
# ==> Mountable engine configurations
# When using Devise inside an engine, let's call it `MyEngine`, and this engine
# is mountable, there are some extra configurations to be taken into account.
# The following options are available, assuming the engine is mounted as:
#
# mount MyEngine, at: "/my_engine"
#
# The router that invoked `devise_for`, in the example above, would be:
# config.router_name = :my_engine
#
# When using omniauth, Devise cannot automatically set Omniauth path,
# so you need to do it manually. For the users scope, it would be:
# config.omniauth_path_prefix = "/my_engine/users/auth"
end
config/initializers/inflections.rb
---
# Be sure to restart your server when you modify this file.
# Add new inflection rules using the following format
# (all these examples are active by default):
# ActiveSupport::Inflector.inflections do |inflect|
# inflect.plural /^(ox)$/i, '\1en'
# inflect.singular /^(ox)en/i, '\1'
# inflect.irregular 'person', 'people'
# inflect.uncountable %w( fish sheep )
# end
#
# These inflection rules are supported but not enabled by default:
# ActiveSupport::Inflector.inflections do |inflect|
# inflect.acronym 'RESTful'
# end
config/initializers/mime_types.rb
---
# Be sure to restart your server when you modify this file.
# Add new mime types for use in respond_to blocks:
# Mime::Type.register "text/richtext", :rtf
# Mime::Type.register_alias "text/html", :iphone
config/initializers/secret_token.rb
---
# Be sure to restart your server when you modify this file.
# Your secret key for verifying the integrity of signed cookies.
# If you change this key, all old signed cookies will become invalid!
# Make sure the secret is at least 30 characters and all random,
# no regular words or you'll be exposed to dictionary attacks.
MovieRecommendations::Application.config.secret_token = '5211d5b8d3df0bdd5c0da37d682b0c7b3cdd126b883bd40977d0207ed6b1a792ced08ff7fe07fe5e54125e730e2e777af13d251c9ab40dd03c6e04a9305cb0a1'
MovieRecommendations::Application.config.secret_key_base = 'b769e938a127e93c07e6bca044df61eefa0349c247b5c278ccc1d0495741e9261f63cc28911027876269a74227825a94f69c58620bc2c584b48a492ba9f32d40'
config/initializers/session_store.rb
---
# Be sure to restart your server when you modify this file.
MovieRecommendations::Application.config.session_store :cookie_store, key: '_recommendation_system_session'
# Use the database for sessions instead of the cookie-based default,
# which shouldn't be used to store highly confidential information
# (create the session table with "rails generate session_migration")
# MovieRecommendations::Application.config.session_store :active_record_store
config/initializers/wrap_parameters.rb
---
# Be sure to restart your server when you modify this file.
#
# This file contains settings for ActionController::ParamsWrapper which
# is enabled by default.