Category Archives: Development

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!

oAuth Twitter for PHP and WordPress developers: Version 2!

Yesterday, I released version 2.0 of our oAuth Twitter PHP class and WordPress plugin.

It’s a simple way of handling all of the oAuth requirements in Twitter’s API v1.1 that become mandatory on 5th March 2013. For more information about the plugin itself, you can read my original post on the first release.

Version 2.0 is vastly improved and allows you to:

  • Use multiple Twitter accounts rather than just the one defined in the configuration
  • Define a custom cache expiry (and allows you to disable it for debug purposes)
  • Pass any custom parameters you want to Twitter’s API, and override the defaults easily

This update is fully backwards compatible with version 1.0. You can either upgrade the plugin using the WordPress admin panel, or just drop the updated class file in — but it will delete your cache the first time it runs, as the format has changed significantly to support the new features.

We suspect many people aren’t yet prepared for Twitter’s great API 1.0 switch off on 5th March 2013, so it’s worth checking any sites you manage or maintain to make sure they are using authenticated calls to Twitter.

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!

How to show comments on a separate page in WordPress

Struggling to give WordPress comments their own page without messing up your URL structure? I know the feeling.

Displaying a post’s comments separately from the main content can be useful in many circumstances. Although less common nowadays, traditionally many blogs chose to feature comments in a pop-up window or lightbox. It can also be desirable for editorial or legal reasons, for caching purposes, or perhaps if you are publishing individually art-directed posts. It can also be handy when using WordPress for a non-blog website.


Continue reading

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

Is Google indexing pages from Twitter and messing with your analytics?

I just Googled for “WordPress RC” to find the release notes for the 3.5 Release Candidate.  I clicked on the result for wordpress.org and was taken to the correct page, nothing out of the ordinary.  I then copied the URL to share in team chat and noticed that the URL was quite long; there were some query string parameters.  The complete URL was:

http://wordpress.org/news/2012/11/wordpress-3-5-release-candidate/?utm_source=twitterfeed&utm_medium=twitter

The utm_source and utm_medium parameters are used by Google Analytics to segment traffic by source.  Normally you would expect to end up on this URL if you clicked from the WordPress Twitter feed.


Continue reading

oAuth Twitter Feed: PHP Library & WordPress plugin

Twitter’s new API 1.1 has been live for a couple of months now and that brings with it a whole new set of requirements for using the Twitter API. From March 2013, everyone displaying tweets must comply with the new terms and update their websites code to be compliant with the new requirements, which includes changes to the way you authenticate.

This basically means you won’t be able to use Javascript to load in tweets for your website directly from Twitter, as all requests must be authenticated.

This is a major problem for the vast majority of websites that are currently using Twitter and one we needed to work around – so we built a PHP class (GitHub), and a WordPress plugin (GitHub), that implements all the new requirements for authentication and gives you an array of tweets out of the other end, for you to use in your WordPress themes, or PHP applications. We built the class and plugin on top of Abraham Williams’s Twitter OAuth class which makes the OAuth stuff really easy.

You can get the plugin from the WordPress plugin directory: oAuth Twitter Feed for Developers.

The plugin implements caching for (by default) 1 hour too, to stop you hitting the API limits which could occur with the new authenticated-only request requirements and protects you from Twitter outages. You can change this yourself in the source code.

It’s definitely for developers though – you only get an array out of it that contains Twitter tweet objects (You’ll find more about them on the Twitter API documentation). You’ll still need to style the output and make it comply with the new display requirements.

The plugin provides a getTweets() function that you can call in your theme files. This returns an array you can then loop over and do whatever you want with it.

      $tweets = getTweets();
      var_dump($tweets);

      foreach($tweets as $tweet){
        var_dump($tweet);
      }

You can specify a number of tweets to return (up to 20) by passing a parameter to the function. For example, to display just the latest tweet you’d request getTweets(1).

This is an early release of the class and plugin, both could offer a lot more functionality.  If you want to get involved, fork the code on GitHub and send us a Pull Request!

Debugging :active, :focus, :hover and :visited states in Chrome

When you interact with an element on a web page, various pseudo classes are applied dynamically that you can use in CSS to define styles. These changes are not reflected in the Chrome inspector in real-time – you can’t select an element, hover over it and see the :hover styles.  In the simple case of changing text colour of an <a> this isn’t a big problem.  However, as soon as you start to use these pseudo classes for more complex purposes, like building complex navigation menus, you hit a point where you really want to be able to inspect those styles.


Continue reading