Skip to content

Instantly share code, notes, and snippets.

@ekumachidi
ekumachidi / list_models.rb
Created February 17, 2020 17:23
List all classes in your rails app
Rails.application.eager_load!
ActiveRecord::Base.descendants # It returns all models and its attributes.
ActiveRecord::Base.descendants.collect(&:name) # It returns only the model names
# If you're using > rails 5.0 you can use the line below
ApplicationRecord.descendants.collect(&:name) # It returns only the model names
@kizzx2
kizzx2 / post.rb
Last active June 26, 2021 12:14
A clean and elegant approach to partial object validation with Rails + Wicked wizards (using session to store the partial object)
class Post < ActiveRecord::Base
attr_accessible :body, :price, :title
validates_presence_of :title
validates_length_of :title, minimum: 10
validates_presence_of :body
validates_numericality_of :price, greater_than: 0
end
@madtrick
madtrick / gist:3917079
Created October 19, 2012 09:06
Warden strategy for Devise
module Devise
module Strategies
class RemoteAuthenticatable < Authenticatable
#
# For an example check : https://github.com/plataformatec/devise/blob/master/lib/devise/strategies/database_authenticatable.rb
#
# Method called by warden to authenticate a resource.
#
def authenticate!
#
@madtrick
madtrick / remote_authenticatable.rb
Created October 19, 2012 08:43
Example module to perform remote authentication with Devise
module Devise
module Models
module RemoteAuthenticatable
extend ActiveSupport::Concern
#
# Here you do the request to the external webservice
#
# If the authentication is successful you should return
# a resource instance