Rails

Using Pow with RVM 1.19′s .ruby-version and .ruby-gemset files

With the upgrade to RVM 1.19 you are asked to convert your old .rvmrc file into .ruby-version and .ruby-gemset files.

You are using ‘.rvmrc’, it requires trusting, it is slower and it is not compatible with other ruby managers, you can switch to ‘.ruby-version’ using ‘rvm rvmrc to [.]ruby-version’ or ignore this warnings with ‘rvm rvmrc warning ignore /Users/danielkehoe/code/railsapps/rails-prelaunch-signup/.rvmrc’, ‘.rvmrc’ will continue to be the default project file in RVM 1 and RVM 2, to ignore the warning for all files run ‘rvm rvmrc warning ignore all.rvmrcs’.

A typical .ruby-version file would contain

ruby-2.0.0-p0

The .ruby-gemset file would have

MyProject

You can add the gemset name into the .ruby-version file as ruby-2.0.0-p0@MyProject but that breaks compatibility with other Ruby version launchers.

Pow needs RVM to be loaded and for it to select the correct Ruby version to run your app with.  You do this with the .powrc file.  Mine looks like this:

if [ -f "$rvm_path/scripts/rvm" ] && [ -f ".ruby-version" ] && [ -f ".ruby-gemset" ] ; then
  source "$rvm_path/scripts/rvm"
  rvm use `cat .ruby-version`@`cat .ruby-gemset`
fi

That’s all there is to it!

Job: Full time Web Developer

Storm is a web development agency based in Bath, UK with a growing reputation.  To meet our ever increasing demand we’re looking for some new talent to join our skilled team.

  • Role: Web Developer
  • Basis: Full time
  • Salary: Based on experience
  • Location: Storm HQ, Bath, UK


Continue reading

How to save the uploaded file name with carrierwave_direct and S3

So you’ve setup carrierwave_direct and you’re happily uploading files to Amazon S3. In this example I’ve mounted CarrierWave on a field called csv_file, but that can be whatever is appropriate to your app.  

You’ve probably got two controller methods

def upload
  @model = Model.new
  @model.save

  @uploader = @model.csv_file
  @uploader.success_action_callback = upload_successful_model_url(@model)
end

def upload_successful
  @model = Model.find(params[:id])

  # Now what??
end

You need to save the file name to the model so that it can be referenced later. The documentation (at the time of writing) offers no indication of how you might go about that. The secret is in the key attribute that CarrierWave adds to your model.

def upload_successful
  @model = Model.find(params[:id])
  @model.key = params[:key]
  @model.save

  redirect_to model_path(@model)
end

Simple. When you know how!

6 Ways to get More Bang for your Heroku Buck While Making Your Rails Site Super Snappy

We love Heroku. It makes deployment so easy and quick. However, it can start to get pricey when you add additional dynos at $35 each a month.

With a small amount of work, you can get a lot more out of your Heroku hosting whilst drastically improving the performance of your site. You might need to spend a little bit of cash on other services, but a lot less than if you simply moved the dyno slider up a few notches, and the result will be much better scalability.

So how do we max out the performance of our Heroku apps? First we stop using Heroku for things it’s bad at, then we let it do more of what it is good at, running your application code.


Continue reading

Using tomdoc to document a scope in a Rails model

I’m playing around with Tomdoc for documenting my latest Rails project.  The documentation is (ironically) a bit thin on the ground.  It’s taking a bit of trial and error to get some things working.  The most recent brainteaser was how to get tomdoc (or even rdoc) to document a scope declared on a Rails model.


Continue reading

Turbo-charging your WordPress site with Turbolinks

At Storm, we use a variety of tools, frameworks and programming languages - we’re committed to being polyglot programmers and to using the right tool for the job!  This gives us a broad view on the world and lets us see what different groups of people are up to.  We’ve been watching the development of Rails 4.0 with interest and one feature in particular has caught our eye: Turbolinks.


Continue reading

jQuery document ready events and TurboLinks

Rails 4 will be shipping with TurboLinks enabled by default.  TurboLinks is a PJAX like library that asynchronously requests the content of the next page and inserts it into the current page’s body instead of requiring a full page reload.   It speeds up page load times nicely.  However, because the page is reloaded, the DOMContentLoaded event is triggered and your jQuery document.ready event wont be triggered.

The Solution

var do_on_load = function() { 
  // do some things 
}
$(document).ready(do_on_load)
$(window).bind('page:change', do_on_load)

You have to listen for the page:change event and bind your function to that too.  Simple.