Ruby Tips #337 – Practicing Ruby goes Public

Today Gregory Brown opened up https://practicingruby.com/ to the public. I have been a subscriber of this resource a little over a year and it has been a great read for the weekends and gaining better understanding of less covered topic in Ruby (ie… not web). There are still some...

Ruby Tips #336 – Turn Rails into a Game Engine

There is great library out for game creation named Gosu. This example show how to turn your Rails application into a Gosu game in five minutes. 1) Create a Rails application, add the gem, bundle and add a window model, $ rails new game_engine # Gemfile gem 'gosu' #...

Ruby Tips #335 – Fallback to Yaml when ENVs aren’t present

To keep secure keys out of repositories we commonly use ENV variables in different environments. The following is an example of a Carrierwave configuration that will fallback to s3.yml when a user doesn’t have ENV variable credentials set for s3 file uploads. The same principle can be used for...

Ruby Tips #334 – Ruby Flow Control and Assignment

Ruby offers flow control and assignment and it can be flipped either on the right or left side of ‘if’ and ‘unless’ statements. if registered and remote_app = RemoteApplications.find(app_id) # do many things end # or ... if remote_app = RemoteApplications.find(app_id) and registered # do many things end

Ruby Tips #333 – Touch Events in Coffeescript (Part 2)

To build on yesterday’s tip let’s look at a simple example indicating the direction of our users touch. # app/assets/javascripts/touch_handler.js.coffee movement = element: $('body') startingPointX: 0 startingPointY: 0 movement.touching = (e) -> e = e.originalEvent touchObject = e.changedTouches[0] point = if e.touches then e.touches[0] else e movement.startingPointX = point.pageX...

Ruby Tips #332 – Touch Events in Coffeescript (Part 1)

Although not Ruby, Coffeescript is part of every Rails developer’s toolkit now, and with front-end development comes the responsibility of responsive design. Today we look at how to grab a moving finger on a mobile device. In part two we will look at how to test the direction of...

Ruby Tips #331 – Lock Down Beta Sites with Before_action

Building beta sites can become cluttered with statements, but Rails before_actions make it easy to lock down sections of web applications without flow control in views. class PagesController < ApplicationController before_action :redirect_unless_live, only: [:tickets, :shows, :press] def press; end def shows; end def tickets; end home # ready for...

Ruby Tips #330 – Lock Down Devise when Using OAuth

If you use devise for authentication management with OAuth and a third party you may need to remove the devise authentication routes and confirm your model won’t be able to create rouge users. This solution will prevent users getting to your authentication routes and prevent non-approved users from entering...

Ruby Tips #329 – Format Ruby Hash in Query Parameters

Yet another way to join to join hash parameters for url construction is to mock Ruby’s join method. parameters = {title: 'president', name: 'Barack'} parameters.map { |i| i * "=" } * "&" #=> "name=Barack&title=president" 🙂