Skip to content

Instantly share code, notes, and snippets.

View lalitlogical's full-sized avatar
💭
I may be slow to respond.

Lalit Kumar Maury lalitlogical

💭
I may be slow to respond.
  • engineer.ai
  • Gurgaon, Haryana, India
View GitHub Profile
@lalitlogical
lalitlogical / custom_devise_mailer.rb
Last active March 21, 2017 07:48
Dynamic subject for Devise mailers (i.e. reset_password_instructions)
class CustomDeviseMailer < Devise::Mailer
helper :application # gives access to all helpers defined within `application_helper`.
include Devise::Controllers::UrlHelpers # Optional. eg. `confirmation_url`
default template_path: 'devise/mailer' # to make sure that your mailer uses the devise views
def reset_password_instructions(record, token, opts={})
opts[:subject] = I18n.t(:'devise.mailer.reset_password_instructions.subject', app_name: ENV['APP_NAME'])
super
end
end
@lalitlogical
lalitlogical / deploy.rb
Last active April 30, 2017 06:16
sunspot solr with help of capistrano 3
# Your other configuration i.e. github repo, branch, deploy_to etc
.........
namespace :deploy do
# Your other configuration i.e. start/stop puma/passanger/any other application server
......
before :updated, :setup_solr_data_dir do
invoke 'solr:symlink'
end
@lalitlogical
lalitlogical / _navbar.html.erb
Created July 4, 2017 10:11
Active proper menu in Rails views
...
<div class="hor-menu ">
<ul class="nav navbar-nav">
<li class="<%= active('dashboard', 'index')%>">
<%=link_to "Dashboard", root_path %>
</li>
<li class="<%= active('organisations,organisation_people')%>">
<%=link_to "Organisations", organisations_path %>
</li>
<li class="<%= active('people')%>">
@lalitlogical
lalitlogical / has_many_through.rb
Last active December 15, 2018 18:11
Custom has many through association in mongo db
module HasManyThrough
extend ActiveSupport::Concern
class_methods do
def define_through associations = {}
class_eval do
associations.each do |model, through_model|
model_name = model.to_s.underscore
define_method "#{model_name}_ids" do
@lalitlogical
lalitlogical / database.yml
Created December 18, 2018 06:10
database yml
default: &default
adapter: postgresql
host: <%= ENV['DB_HOST'] %>
encoding: unicode
pool: 5
username: <%= ENV['DB_USERNAME'] %>
password: <%= ENV['DB_PASSWORD'] %>
database: <%= ENV['DB_DATABASE'] %>
template: template0
@lalitlogical
lalitlogical / carrierwave_aws.rb
Created December 18, 2018 06:10
carrierwave aws
CarrierWave.configure do |config|
if Rails.env.development? or Rails.env.test?
config.asset_host = "http://localhost:#{(ENV['PORT'].try(:to_i) || 3000)}"
config.storage = :file
else
config.storage = :aws
config.aws_bucket = ENV['S3_BUCKET_NAME'] || "contracts-#{Rails.env}"
config.aws_acl = 'public-read'
# Optionally define an asset host for configurations that are fronted by a
@lalitlogical
lalitlogical / sidekiq.rb
Created December 18, 2018 06:12
sidekiq
rails_root = Rails.root || File.dirname(__FILE__) + '/../..'
rails_env = Rails.env || 'development'
redis_config = YAML.load(ERB.new(File.read("#{Rails.root}/config/redis.yml")).result)[rails_env]
redis_config.symbolize_keys!
Sidekiq.configure_server do |config|
config.redis = { url: "redis://#{redis_config[:host]}:#{redis_config[:port]}/12" }
end
Sidekiq.configure_client do |config|
@lalitlogical
lalitlogical / searchkick.rb
Created December 18, 2018 06:13
searchkick mongoid
Searchkick.class_eval do
# Your new methods here
def self.load_records(records, ids)
records =
if records.respond_to?(:queryable)
# Mongoid 3+
records.queryable.for_ids(ids)
elsif records.respond_to?(:primary_key)
# ActiveRecord
records.where(records.primary_key => ids) if records.primary_key
@lalitlogical
lalitlogical / rails_admin_delete_override.rb
Created December 18, 2018 06:15
rails admin delete override
# config/initializers/rails_admin_delete_override.rb
module RailsAdmin
module Config
module Actions
class Delete < RailsAdmin::Config::Actions::Base
RailsAdmin::Config::Actions.register(self)
register_instance_option :visible? do
!bindings[:object].respond_to?(:destroyable?) || bindings[:object].destroyable?
end
@lalitlogical
lalitlogical / customise_devise.rb
Created December 18, 2018 06:19
customise devise for otp or reset password token
module CustomiseDevise
extend ActiveSupport::Concern
included do
attr_accessor :project_name, :mailer_host_name, :confirmation_required, :confirmation_type
after_create :send_confirmation_instructions, if: :confirmation_required?
class_eval do
def confirmation_required?
!!confirmation_required