Application Mailers in Rails

I recently learned how to setup mailers for the current app I am working on. It turns out that it is fairly easy. The hard part is setting the proper configurations. Lets start with our development environment.

environments/development.rb

config.action_mailer.raise_delivery_errors = true
config.action_mailer.default_url_options = { :host => 'localhost:3000'}

config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
address: 'smtp.gamil.com',
port: '587',
domain: 'gmail.com',
authentication: 'plain',
enable_starttls_auto: true,
user_name: ENV['GMAIL_USER_NAME'],
password: ENV['GMAIL_PASSWORD']
}

Next the production settings

Continue reading

Params and Object Attributes

I was working on a model for one of my rails projects and figured out a process that seems quite useful. I had a form that had 7 check boxes pertaining to the days of the week. I wanted to update an object that had corresponding attributes for each day as booleans. I.e. object: mon=>false tue=>false etc. If the boxes are checked when the form is submitted I want to update the corresponding object attribute to equal true. The best way I found to do this was to iterate over the params, and update the corresponding attribute. Here is how I did it.

for i in params
 if params[i] == 'on'
   @performance[i] = true
 elsif params[i] == ''
   @performance[i] = false
 end
end

Instead of looking for each specific attribute in params, this is how you compare your params against your object attributes.  If you are curious how my form works I use a hidden field to tell my object that the box is unchecked by giving it a value of “”. This way the unchecked boxes still pass as a parameter when the form is submitted.

<%= hidden_field_tag :mon, '' %>
<%=
check_box_tag :mon %>

Happy coding!

Sidekiq-Cron

If you haven’t already, check out the Rails application I’m writing about www.frontpagespin.com. With the implementation of headless Chrome that I discussed in my last post I basically had my application complete. I could just call a command, upload my screenshots to an Amazon bucket, and call them to my view from a database. Why not make it even easier? I could use Sidekiq and Sidekiq-Cron to schedule a worker to run the command for me at a set time every day. This way my application can run 100% autonomously.

Sidekiq is a worker tool used to process tasks in the background of an application. Sidekick-Cron is just a scheduling add-on that uses Cron notation (* * * * *) to schedule Sidekiq workers. I had some trouble configuring both of these on Heroku  so I’m going to give some instructions for someone interested in doing something similar to what I did.

Continue reading

Headless Chrome

After the Rails tutorial I worked through I wanted to start a project that I had personal interest in. The idea I settled on was to create a site that gathered media headlines from different news sites so users could compare the way various news organizations prioritized stories.

To accomplish this I wanted my Rails application to take screenshots and load them on a view to compare. After some research it seemed like there were a lot of different techniques to accomplish this. I could use Phantomjs, or Selenium to drive a web browser. There were also several gems that offered the functionality. I also came across headless Chrome.  Continue reading

Step 1: Learn Rails

Why Rails? What is Rails? I learned how to use Ruby on Rails mainly because its the web framework my cousin is most familiar with. Here is a description from http://rubyonrails.org

Rails is a web application development framework written in the Ruby language. It is designed to make programming web applications easier by making assumptions about what every developer needs to get started. It allows you to write less code while accomplishing more than many other languages and frameworks. Experienced Rails developers also report that it makes web application development more fun.

I had no previous experience using the Ruby language, or any other web app framework. Most of my minimal programming background was in Python and JavaScript. Fortunately, you don’t need much experience to learn Rails. I used a free book from https://www.railstutorial.org/book to learn everything I needed to start my own web application project. It was easy for me to jump right into, however if you’re windows user it might take a bit longer to get setup. There are lots of tutorials out there on how to setup a vm to run Linux, which is recommended because most Ruby on Rails tutorials and dependencies work best on Linux.  Continue reading

How I Got Here

I’m going to keep things short. I, like many before me, quit my job in pursuit of a new task. It wasn’t difficult giving up swing shift at a grocery warehouse. I’m fortunate enough to have kept myself out of debt and saved enough money to walk away and start over. A few weeks later I bought a ticket to Thailand, and that’s where I’m sitting right now. No, I’m not trying to become a blogger. No, I’m not a “digital nomad”. My cousin lives here.

He’s working on growing his software company, and lives in Thailand because it’s affordable and where his wife is from. He didn’t exactly offer me a job, but he did offer to mentor me. I consider myself a seize the opportunity kind of person. Before I left home my cousin and I talked about what I should try to accomplish while I was here.

I’ve been in Thailand for 3 weeks now. I’d like to share what I have been working on.