| Class | ApplicationController |
| In: |
app/controllers/application_controller.rb
|
| Parent: | ActionController::Base |
# File app/controllers/application_controller.rb, line 28
28: def clear_track_set_get
29: track
30: set_locale
31: get_stats
32: @logged_in = logged_in?
33: @admin_user = @logged_in && admin_user?
34: headers['P3P'] = %|CP="CAO PSA OUR", policyref="#{Constants::Urls::P3P}"|
35: end
# File app/controllers/application_controller.rb, line 37
37: def closed
38: if request.xhr?
39: render :update do |page|
40: page.redirect_to(about_path)
41: end
42: else
43: redirect_to(about_path)
44: end
45: end
# File app/controllers/application_controller.rb, line 89
89: def detect_content_type(file)
90: ext = File.extname(file).delete('.')
91: ext.length > 2 ? Technoweenie::AttachmentFu.content_types.detect { |obj| obj =~ /#{ext.downcase}/ } : nil
92: end
# File app/controllers/application_controller.rb, line 98
98: def fetch_user_items(active_only = true)
99: conditions = active_only ? { :active => true } : {}
100: user_item_ids = current_user.item_ids(:conditions => conditions) if logged_in?
101: @user_items = logged_in? ? Item.by_win_percent(
102: :conditions => { 'items.id''items.id' => user_item_ids },
103: :limit => Constants::Config::TOP_ITEMS_FOR_USER
104: ) : []
105: response_counts = Response.all(
106: :select => 'items_responses.item_id, COUNT(*) AS responses',
107: :conditions => { 'items_responses.item_id''items_responses.item_id' => @user_items.map(&:id) },
108: :joins => "INNER JOIN items_responses ON (items_responses.response_id=responses.id)",
109: :group => "items_responses.item_id"
110: ).inject({}) { |hash, el| hash[el.item_id.to_i] = el.responses; hash }
111: @user_item_info = @user_items.inject({}) do |hash, item|
112: hash[item.id] = "<strong>#{response_counts[item.id]}</strong>"
113: hash
114: end
115: end
# File app/controllers/application_controller.rb, line 47
47: def flag_obj(params)
48: params[:visit_id] = current_visit_id!
49: flag = Flag.create(params)
50: flag.suspend unless flag.new_record?
51: flag
52: end
# File app/controllers/application_controller.rb, line 72
72: def get_stats
73: @total_votes ||= Response.count(:conditions => { :active => true }).to_s
74: @total_items ||= Item.count(:conditions => { :active => true }).to_s
75: end
# File app/controllers/application_controller.rb, line 77
77: def save_profile_questions(profile, params)
78: return unless params
79: profile_questions = profile.profile_questions
80: params.each do |name, value|
81: if q = profile_questions.detect { |pq| pq.name == name }
82: q.update_attribute(:value, value)
83: else
84: ProfileQuestion.create(:profile_id => profile.id, :name => name, :value => value)
85: end
86: end
87: end
# File app/controllers/application_controller.rb, line 94
94: def setup_mail_params(mail)
95: mail.merge(:user_id => current_user.id, :visit_id => current_visit_id!)
96: end
# File app/controllers/application_controller.rb, line 65
65: def setup_user
66: self.locale = current_user.profile && current_user.profile.locale
67: assign_locale
68: assign_prompt
69: create_visit
70: end
temp file creator
# File app/controllers/application_controller.rb, line 118
118: def temp_file_for_url(url)
119: path = "#{Constants::Config::DIR_PATH}/#{File.basename(url)}"
120: url = URI.parse(url)
121: Net::HTTP.start(url.host, url.port) do |http|
122: resp = http.get(url.path)
123: open(path, "wb") { |file| file.write(resp.body) }
124: end
125: return nil unless File.exists?(path)
126: data = ActionController::UploadedTempfile.new(File.basename(path))
127: data.content_type = detect_content_type(path)
128: data.original_path = path
129: FileUtils.copy_file(data.original_path, data.path)
130: [path, data]
131: rescue URI::InvalidURIError
132: false
133: end
# File app/controllers/application_controller.rb, line 54
54: def track
55: params_ = params.clone # don't corrupt real params
56: Tracking.create(
57: :visit_id => current_visit_id!,
58: :controller => params_.delete(:controller),
59: :action => params_.delete(:action),
60: :mouse => params_.delete(:mouse),
61: :parameters => params_.inspect
62: )
63: end