Skip to content

Instantly share code, notes, and snippets.

@superbilk
superbilk / confirmations_controller.rb
Created March 1, 2014 11:39
Please have a look at the changes I made in do_show and do_confirm in the confirmations_controller.rb (Related question: https://groups.google.com/forum/#!topic/plataformatec-devise/4amIRvFCcxY)
# /app/controller/confirmations_controller.rb
class ConfirmationsController < Devise::ConfirmationsController
skip_before_filter :authenticate_user!
# PUT /resource/confirmation
def update
with_unconfirmed_confirmable do
if @confirmable.has_no_password?
@confirmable.attempt_set_password(params[:user])
if @confirmable.valid?
@superbilk
superbilk / gist:5137493
Last active December 14, 2015 19:38
How do I refactor this? DEPRECATION WARNING: Relation#calculate with finder options is deprecated. Please build a scope and then call calculate on it instead. (called from averages at /app/models/star.rb:7) Code is simplified.
class Star < ActiveRecord::Base
default_scope order: 'registered_at DESC'
scope :registered_before, ->(days) { where("registered_at >= ?", days.days.ago) }
def self.averages days = 90
registered_before(days).average(:stars, group: "DATE(registered_at, '+1 day')")
end
end