Skip to content

Instantly share code, notes, and snippets.

View rajcybage's full-sized avatar

Rajars rajcybage

View GitHub Profile
heroku pg:backups capture
heroku pg:backups public-url b005 --app myapp #b005 is get from the first command
#get the public url from above just use curl or paste in browser to ge tthe dump stroe it in C:\Users\rajarshi.das\Downloads\pg_dump_new_2.dump
"C:\Program Files\PostgreSQL\9.6\bin\pg_restore.exe" -h localhost -U postgres -v -d mylocaldatabase "C:\Users\rajarshi.das\Downloads\pg_dump_new_2.dump"
Sure is!
We can disable generation of helpers and assets using the following configuration block in our config/application.rb file:
config.generators do |generate|
generate.helper false
generate.assets false
end
Check out the Rails guide to Configuring Generators for all the available generator specific options.
````
# app/validators/safe_for_work_validator.rb
class SafeForWorkValidator < ActiveModel::EachValidator
BAD_WORDS = %w(darn gosh heck golly)
def validate_each(record, attribute, value)
if BAD_WORDS.any? { |word| value.include?(word) }
record.errors[attribute] << (options[:message] || "is not safe for work!")
end
end
@rajcybage
rajcybage / Gemfile
Last active January 5, 2016 08:26 — forked from pcreux/Gemfile
Fast Rails + Heroku Configuration
group :production do
gem 'pg' # postgresql
gem 'unicorn'
# Enable gzip compression on heroku, but don't compress images.
gem 'heroku-deflater'
# Heroku injects it if it's not in there already
gem 'rails_12factor'
{
"auto_complete_commit_on_tab": true,
"bold_folder_labels": true,
"drag_text": false,
"draw_white_space": "all",
"ensure_newline_at_eof_on_save": true,
"font_size": 15.0,
"highlight_line": true,
"highlight_modified_tabs": true,
"ignored_packages":

An application I'm working on has two different types of Devise users, but I want both types of users to be able to use the same sign in form. Devise doesn't make this easy.

You could argue that I really should have a single user type with a role attribute, but the app is far enough along that I don't want to change that early design decision. It could be changed later if more pain points are discovered.

You could also argue that I shouldn't use Devise, but it's still the de facto authentication standard for Rails applications.

In this example, you can sign in as either a User or an AdminUser. This application only has two types of user, but this example could be extended to support any number of them more gracefully.

#/app/mailers/user_mailer.rb
def welcome (current_user)
unless current_user.nil?
mail(
:from => "myid@gmail.com",
:to => current_user.email,
:subject => "Thank you for signing"
)
else
mail(