developer, designer, consultant

quicktip

Rails 3.1 — Using ERB/HAML/etc within a Coffeescript JS file

Stamped: 28 May 2011 | Show comments

Need to use some information from your application in your new Coffeescript file? All you have to do is rename it with .erb.coffee or ..coffee instead of .coffee. This lets you do things like

$ ->
    $('#currency_select').change ->
        window.location = window.location.pathname.replace(/^\/(<%=Country.currencies.keys.join '|'%>)|(?!(<%=Country.currencies.keys.join '|'%>))\//i, '/'+$(this + "option:selected").text())

The best part about it is that Rails still knows when to generate the file, it doesn't do it each time! The only thing you can't directly access are the routes (e.g. root_path(), etc), but a gem called js:routes can take care of that for you.

tags: rails, coffeescript, quicktip

Rails 3.1 — 'load_missing_contant': Expected ... to define ... (LoadError)

Stamped: 28 May 2011 | Show comments

Seeing this error?

This is a simple one to fix. I had two Classes of the same name but with different scopes, one was a model and the other a class in a separate module under lib. You have three options in this scenario:

  1. Choose more appropriate names

  2. Move the module out of lib into a gem

  3. Rename the filename of the Class under the lib/ folder, while retaining the same class name.

tags: rails, quicktip

Cucumber, capybara, lightboxes, and you

Stamped: 21 Oct 2010 | Show comments

Selenium wasn't playing very nice with lightboxes during one of my tests, it just said it wasn't visible! Thanks! That helps all you have to do is wait silly:

When I wait until I can see "new_category"

And the step definition:

When /^I wait until I can see "([^"]*)"$/ do |selector|
  page.has_css?("#{selector}", :visible => true)
end
tags: quicktip, cucumber, capybara

Cucumber, capybara, and checking for the existence of selected options within a select box

Stamped: 21 Oct 2010 | Show comments

Checking for a selected option within Cucumber/Capaybara is quite simple:

Then "hello" should be selected for "article_category_id"

And the step definition:

Then /^"([^"]*)" should be selected for "([^"]*)"$/ do |value, field|
  assert page.has_xpath?("//option[@selected = 'selected' and contains(string(), '#{value}')]") 
end

You could easily extrapolate this for use within an unselected value, just by removing the selected bit:

Then /^"([^"]*)" should be seen within "([^"]*)"$/ do |value, field|
  assert page.has_xpath?("//option[contains(string(), '#{value}')]") 
end
tags: quicktip, cucumber, capybara
recent entries
Rails — A faster way for next and previous links on a post, article, or any model
The awkward things Siri says
Node.js — Getting oAuth Up and Running Using Express.js and Mongoose
Node.js — Getting oAuth Up and Running Using Express.js, Railway.js and Mongoose
Migrating from Rails 3.1 RC4 to RC5 using Heroku's Cedar Stack (also compass, unicorn, and sendgrid)
Random Freeze Fix for GTX 460 in 10.6 (osx86)
Wasted on Steam - an analytic tool for the Steam platform
Rails 3.1 — SQL logging to STDOUT during testing (with rspec, test::unit, or cucumber)
Rails 3.1 — Using ERB/HAML/etc within a Coffeescript JS file
Rails 3.1 — 'load_missing_contant': Expected ... to define ... (LoadError)
View the entire archive of articles