Posts Tagged ‘rails’

Running jQuery code from Ruby using ExecJS-Async

9.4.11 by eric

pipes

Last week I wrote a post about using the Asset Pipeline outside of Rails because we needed to test answers for Code School’s upcoming Zombies 2 course. But we also need a way to test javascript (that uses jQuery) that manipulates a DOM, and all from inside of Ruby.

ExecJS to the rescue

ExecJS is a ruby gem that lets you run JavaScript code from Ruby. It does this by using the best javascript runtime available to evaluate Javascript and returning the result in Ruby! For example:

ExecJS.eval "'red yellow blue'.split(' ')"
# => ["red", "yellow", "blue"]

Rad! Or you can use it to compile a block of javascript and then call it later, like this:

context = ExecJS.compile "var run = function(foo) { return foo + foo }"
context.call 'run', 'bar'
# => 'barbar'

Read the rest of this entry »

Using the Asset Pipeline outside of Rails – Serving CoffeeScript and SASS

8.28.11 by eric

In our upcoming Rails for Zombies 2 Code School course, we have a couple of challenges that make use of Rails 3.1 new Asset Pipeline. The Asset Pipeline is the thing in Rails that serves up your javascript, images, and stylesheets. But it can also compile CoffeeScript into Javascript, or SASS into CSS.

And so we wanted to teach people a little bit of CoffeeScript/SASS in Rails for Zombies 2. But that means we have to have a way to test CoffeeScript/SASS. We accomplished this by extracting the bits in Rails 3.1 that implement the pipeline and used them to serve and compile CoffeeScript into Javascript and SASS into CSS.

Read the rest of this entry »

Rails 3 Interview

8.16.10 by Gregg Pollack

In February of this year Nathaniel Bibler and I flew out to Engine Yard in San Francisco to spend a day with Carl Lerche and Yehuda Katz. The purpose of the trip was to interview both of them about Rails 3, doing some research for the upcoming Rails 3 Screencasts. We recorded the entire interview on about 5 hours of video, most of which would put you to sleep. Recently I dug out the footage and put it together into a 20 minute video which you can see below. I apologize in advance for the audio, I know it’s not the best.

Read the rest of this entry »

Census: Rails Demographics Collection

4.16.10 by Mark Kendall

Much like the United States government, your Rails application may need to collect demographics data for each of its users. That’s where the Census gem comes in. It’s a Rails engine that provides:

  • an administration interface for defining the data you’d like to collect
  • extensions on your User model and forms for collecting users’ responses
  • a simple way to search for users based on their responses

In this post, we’ll take a look at Census by extending a simple Rails app to include a user satisfaction survey.

Read the rest of this entry »

Getting Started with the Rails 3 BugMash

1.15.10 by Nathaniel Bibler

This is a short writeup to help everyone get ready for the Rails 3 BugMash. The following steps and notes were taken to help you put together a new, working Rails 3 application. Many of these steps will match Yehuda Katz’s post on getting started.

Read the rest of this entry »

Scaling Rails – On The Edge – Part 3

11.25.09 by Gregg Pollack

You can now watch the last episode of the three part series covering some of the newest libraries for helping you scale your Rails apps. This screencast dives into three new libraries that each can help you scale your website in a different way. We start with an introduction to rubber, an alternative to chef / chef deploy which can help you to quickly deploy a server cluster in the cloud. Then we take a look at Cloud Crowd, a completely Ruby background processor which can perform map reduce. Lastly we dive into a web service called Mad Mimi, which isn’t just useful for maintaining mailing lists, but can also host all of your app’s emails.

Scaling Rails

Download this Episode – (81.7 MB, 17:07, MP4)

In this second episode I introduce three tools:

  • rubber – A capistrano/rails plugin for deploying to Amazon ec2.
  • Cloud Crowd – Background job processor with map reduce.
  • Mad Mimi – Scale your mailing lists / campaign emails

These screencasts look great on your iPhone, so I highly encourage you to subscribe and download them on iTunes. Also, to keep up to date on the latest news in the Ruby and Rails community, be sure to check out the Ruby5 podcast if you haven’t already. Thanks!

Scaling Rails – On The Edge – Part 2

11.13.09 by Gregg Pollack

Last week I released the first of a three part series covering some of the newest libraries for helping you scale your Rails apps. Today I bring you part two of the series which starts with a discussion of this article from Sudara Williams. In the article Sudara talks about the true reason why Rails apps can start hogging memory, and then suggests three tools to help prevent this bloat. In this screencast I show you how to use rack-bug, memorylogic, and oink, the three tools he recommends.

Scaling Rails

Download this Episode – (49.5 MB, 10:21, MP4)

In this second episode I introduce three tools:

  • rack-bug – Rails middleware which gives you an informative toolbar in your browser.
  • memorylogic – Gives your logger a memory footprint.
  • oink – Provides metrics on your worst memory bloated requests.

These screencasts look great on your iPhone, so I highly encourage you to subscribe and download them on iTunes. Also, to keep up to date on the latest news in the Ruby and Rails community, be sure to check out the Ruby5 podcast if you haven’t already. Thanks!

Scaling Rails – On The Edge – Part 1

11.5.09 by Gregg Pollack

It’s been a while since I’ve released a new Scaling Rails Screencast, but this morning I’m happy to announce that three new screencasts have been produced and the first one is being released today. In these screencasts I’m going to introduce you to 9 new Ruby and Rails libraries which can help you scale your rails application.

Scaling Rails

Download this Episode – (41.4 MB, 8:49, MP4)

In this first episode I introduce three tools:

  • Bullet – Help you reduce the number of queries with alerts (and growl).
  • Rails Indexes – Rake tasks to find missing indexes.
  • Scrooge – SQL query optimizer, so you query for only what your page needs.

These screencasts look great on your iPhone, so I highly encourage you to subscribe and download them on iTunes. Also, to keep up to date on the latest news in the Ruby and Rails community, be sure to check out the Ruby5 podcast if you haven’t already. Thanks!

The Rails State Machine

8.5.09 by Nathaniel Bibler

Go and StopRuby on Rails recently added a built-in ActiveRecord::StateMachine implementation and even more recently tied it in to ActiveRecord. And, for being a built-in library, it’s pretty damned fully-featured. Really, if this one doesn’t do it for you, then you probably need to write it yourself, anyway.

And, if you’re thinking that you don’t know what a state machine is, or think that you’ve never used one, think again. If you’ve ever used the restful_authentication plugin, you’ve probably used a state machine. In that library, Users can be pending, active, inactive … It’s all the same object, just acting differently depending on its current situation. That, in a nutshell, is a state machine.

Read the rest of this entry »

Set Up Your Server Right, Part 1

8.5.09 by Thomas Meeks

A little background

Server Rack

Unix administrators have been dealing with the same problems for a long, long time. Users and programs contending for resources, outside attackers trying to get in, crashing services. You name it. There are a lot of excellent utilities out there to handle all of these issues. Unfortunately, they go mostly unused.

Ever have an application, of any language, eat up memory or disk space to the point of slowing the entire system to a crawl? Seen a security breach in one web application compromise a whole server? Had a server encounter performance problems that seem to disappear by the time you make it into top? I’ve joined a number of projects where problems like these are constant, nagging issues. They really don’t need to be.

Read the rest of this entry »