Web Programming - Part 5: Views
# Web Programming
# Add-ons
*$ Terminal* heroku addons:add cloudinary
Switch to your TechGirlz app *$ Terminal* $ git remote rm heroku $ git remote add heroku \ git@heroku.com:tg-YOUR_FIRST_NAME.git $ git push heroku master $ heroku run rake db:migrate
*Gemfile* gem 'carrierwave' gem 'cloudinary' *$ Terminal* bundle
*$ Terminal* rails generate uploader image *app/uploaders/image_uploader.rb*
class ImageUploader < CarrierWave::Uploader::Base
  if ENV['CLOUDINARY']
    include Cloudinary::CarrierWave
  else
    storage :file
  end
end
(remove everything else)
*app/models/post.rb* attr_accessible :desc..., :image_cache mount_uploader :image, ImageUploader *app/views/posts/_form.html.erb*
<%= f.file_field :image %>
<%= f.hidden_field :image_cache %>
Sending email
Configure your app *config/environments/production.rb*
config.action_mailer.smtp_settings = {
  :address        => 'smtp.sendgrid.net',
  :port           => '587',
  :authentication => :plain,
  :user_name  => ENV['SENDGRID_USERNAME'],
  :password   => ENV['SENDGRID_PASSWORD'],
  :domain         => 'heroku.com'
}

config.action_mailer.default_url_options =
  { :host => "tg-YOURNAME.herokapp.com"] }
Make a mailer *$ Terminal* rails generate mailer notifications new_post Now look in app/mailers/notifications.rb And app/views/notifications/new_post.text.erb
Send the email from the controller
class PostsController
  def create
    ...
    if @post.save
      Notifications.new_post.deliver
    end
  end
end
Look in your server console to see it
From: from@example.com
To: to@example.org
Message-ID: <4f6096a992767_1ff43ff11b9325c862492@schaffer.local.mail>
Mime-Version: 1.0
Content-Type: text/plain;
 charset=UTF-8
Content-Transfer-Encoding: 7bit