Articles tagged 'ruby'

  • Rails 3.1: Treating your '.swf' files as assets

    January 12, 2012


    This post was originally published in the Rambling Labs Blog on January 12, 2012.


    This week, I’ve been deploying one of my current Ruby on Rails projects to WebFaction. For what we found, it’s definitely one of the best options out there for shared hosting with Python and Ruby.

    The application being deployed happened to contain some static flash content (not my idea of course :P), which so far we had put in the public/ directory and had served with no problems so far, while testing locally and on Heroku. However, when we were testing it out on WebFaction, it kept returning 404 errors.

    So, googling for a while, I stumbled into the swf_fu gem. It’s main function is to treat the swf objects as just another asset in the application. So,…

    Continue Reading →

  • Rails 3.1 - Adding custom 404 and 500 error pages

    January 5, 2012


    This post was originally published in the Rambling Labs Blog on January 5, 2012.


    As I said when announcing the Rambling Labs new site, we’ve been learning a lot of stuff while building it.

    Something that we didn’t have the chance to implement on our current projects (but that we will be including soon), is adding custom error pages to the site. So far, what we were looking for was two things: a custom 404 error page and a custom generic 500 error page.

    For the experience I have now with Rails, I thought this would be a piece of cake. Well, in fact… it would’ve been if we were using Rails 2. But guess what? The error handling behavior in Rails 3 is not what you would expect. Even worse, it’s broken for routing errors!

    For what I could…

    Continue Reading →

  • Replacing ERb with HAML on your Rails application generators

    January 5, 2012


    This post was originally published in the Rambling Labs Blog on January 5, 2012.


    As you may know, we’ve been using HAML lately for our views.

    Since I don’t plan to use ERb for my views anytime soon, I want HAML to fit in as smoothly as possible. Luckily, there is a way to replace ERb as the default generated view.

    Just add this line to your Gemfile:

    gem 'haml-rails'
    

    And you should be good to go!

    Now, when you run rails generate controller test method_one method_two, you should see something like this:

          # ...
          invoke haml
          create app/views/test
          create app/views/test/method_one.html.haml
          create app/views/test/method_two.html.haml
          # ...
    

    Way easier than what I thought it would be. But you know, that’s…

    Continue Reading →

  • Generating your site menu with the 'simple-navigation' gem

    January 3, 2012


    This post was originally published in the Rambling Labs Blog on January 3, 2012.


    One of the cool things I learned while building our new site was how to generate your site navigation menu without having to do the highlighting logic yourself.

    There’s a great gem out there for this called simple-navigation, which you can find on GitHub. It’s easy to set up and use, so you will probably do what you need to do really quick. To install, add it to your rails application Gemfile:

    gem 'simple-navigation'
    

    Then, run bundle install. After it’s installed, generate the configuration file for it, which will be the config/navigation.rb, with the following:

    rails generate navigation_config
    

    Go ahead and open the config/navigation.rb file, and add your…

    Continue Reading →

  • Using RVM within a cron job

    December 16, 2011


    This post was originally published in the Rambling Labs Blog on December 16, 2011.


    Long time no post! I’ve been really busy these days with some projects. Yet, here I am again, so here it goes.

    A couple of days ago, I started working on a big story in one of those projects I’m currently working on. It’s one of those things that needs to be run a couple of times a day… yeah, a scheduled background job.

    Basically, what it need to do is check some database records, check their expiration date against the current date, and take some actions for each one of the expired ones. Simple enough, right?

    I went ahead and wrote a rake task that would do the heavy work. Something like this:

    task :check_expired_records do
      Record.where('expired =…

    Continue Reading →

  • Installing the capybara-webkit gem

    October 31, 2011


    This post was originally published in the Rambling Labs Blog on October 31, 2011.


    To install the capybara-webkit gem, you need to have the libqt4-dev installed. So run:

    apt-get install libqt4-dev
    gem install capybara-webkit
    

    You should be good to go!

    Continue Reading →

  • Rails 3.1 - Translating routes

    October 26, 2011


    This post was originally published in the Rambling Labs Blog on October 26, 2011.


    Today, I was wondering if there would be a way to add translated routes automatically in Ruby on Rails. This is for a project I’m currently working on, whose users speak mostly spanish, so I want to make them happy with urls like “/contacto”, “/quienes-somos” and “/trabajos/1” instead of “/contact”, “/about-us”, and “jobs/1”.

    So, I googled and there it was: the i18n_routing gem.

    This reminded me one more time how awesome is the Ruby community, which is definitely one of the main reasons why I’m loving Ruby and Rails so much.

    So back on topic, the gem is easy to install, and only depends on the i18n gem. Run gem install i18n_routing and you should be good…

    Continue Reading →

  • The nokogiri gem and the "libxslt is missing" error

    October 17, 2011


    This post was originally published in the Rambling Labs Blog on October 17, 2011.


    I ran into this issue today. But this one’s easy. Just run the following command and install the gem again:

    apt-get install libxslt1.1 libxslt1-dev libxslt-ruby
    

    That’s it! It should work fine now :).

    Continue Reading →

  • Refinery CMS, rails 3.1.1 and the Operation not permitted error Errno::EPERM

    October 14, 2011


    This post was originally published in the Rambling Labs Blog on October 14, 2011.


    The last couple of days, I’ve been trying to set up Refinery CMS for a project I’m working on. I’ve made a couple of Stack Overflow questions about which ruby on rails CMS supports multiple languages and custom types.

    Answers to both questions were directing me to Refinery CMS, so I had to test it out. But… I wanted it to be on rails 3.1 (either 3.1.0 or 3.1.1). So I googled for a while and found that Refinery CMS edge on github does support rails 3.1.

    So I set up my Refinery CMS local test under my Ubuntu virtual machine by first downloading the edge code from github, like this:

    git clone git://github.com/resolve/refinerycms.git ~/refinerycms-edge
    

    Then…

    Continue Reading →

  • Rails 3.1 "rails console" fails with "no such file to load -- readline"

    October 12, 2011


    This post was originally published in the Rambling Labs Blog on October 12, 2011.


    Yesterday, I was trying to run the rails console command on Ubuntu with ruby 1.9.2 and rails 3.1, without any success. I was getting a no such file to load -- readline error. This kind of error was sort of familiar for me (I had the common no such file to load -- zlib and the not so common no such file to load -- openssl a while ago). So this was probably another package that I was missing.

    Turns out that as I found in a Stack Overflow question, I needed the libreadline-dev, which I didn’t have installed. But I also needed to recompile ruby, seriously!?

    This is where rvm comes to the rescue, and why I love so much to have rvm installed :D. You only need…

    Continue Reading →