To intercept emails in specific environments such as development, testing, or staging, we need to write some logic to do so.
module MailInterceptor
def self.delivering_email(message)
# This will be the email that live emails will be sent to
message.to = ['your-email@mail.com']
# Set the cc and bcc to be nil to avoid sending out real emails
message.cc = nil
message.bcc = nil
# Change the from if you want a di...
If you have a ton of uploaded files you need to have a visitor download, you will want to compress said information to decrease size and combine many files into one single zip. We will do this using the rubyzip gem. Keep in mind that if the files are audio or video, compressing them may not have any effect on the size.
We will first add the gem to our project.
# Gemfile
gem "rubyzip"
= link_to 'Download Zip', route_path(format: ...
Sometimes when you have a project, you'll want to run really long scripts and have them daemonized and running in the background. This allows your server to scale and not hang a http request and cause long latency requests on your box.
Let's install a few gems that will help us do exactly this. I chose to use delay jobs gem over sidekiq, because I felt it would be better for my usage of it. Keep in mind that active job was added in Rails 4.2, so if you are running a versi...
# Gemfile
gem 'omniauth-facebook'
rails g migration AddOmniauthToUsers provide...
Say we have a column in our users table that we are no longer needing, we can generate a migration and add any needed information afterwards.
rails g migration RemovePhoneNumberFromUsers phone_number:string
rails g migration RenamePhoneNumberFromUsers
rails g migration AddCommentableToComments body:text commentable:references{polymorphic}
...
To save database information as a csv, we will need to require the rails csv library in the controller we are going to use it in. You also need to add the format in your view method you need it in.
# UsersController.rb
require 'csv'
def index
# Your Code
@users = User.all
respond_to do |format|
format.html
format.csv
end
end
Then in your index.csv.erb view file, you will need to add in the rows and columns you want to be displ...
If you ever want to connect to your own server or someone else's over your ethernet, use the following command in your terminal to start your server:
rails s -b 0.0.0.0 -p 3000
Wanting to run two different rails servers at once on the same machine? Simply change the ports the are running on to have them run simultaneously.
rails s -p 3000
rails s -p 4000
If you need to add any images to your rails app with carrierwave or in ...