Articles tagged 'rails 3.1'

  • 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 →

  • Writing elegant HTML with HAML

    January 4, 2012


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


    Another cool thing that we learned while building the new Rambling Labs site was HAML. It’s a markup language that is based on the premise that ‘Markup should be beautiful’, in their own words.

    It’s very easy to install, just add gem 'haml' to your Gemfile and run bundle install. To use it, replace your view_name.html.erb file with a view_name.html.haml file.

    Like SASS and CoffeeScript, to achieve the beauty it professes, HAML uses indentation to determine what it should do next. This means, and you guessed it, that it writes beautifully.

    Compare this ERb file:

    <div id="single_post">
      <h2 class="post_title"><%= link_to post.title, post %></h2>
      <div 

    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 →

  • Stripping down Rails 3.1: Using only the database migrations

    November 23, 2011


    This post was originally published in the Rambling Labs Blog on November 23, 2011.


    The current project I’m working on is not using Ruby on Rails, but I still want to use ActiveRecord Migrations for the database changes.

    There are some options out there for this, and most people that I read about and had this issue just use the activerecord gem and set up their rake tasks.

    I don’t want to write my own rake tasks, since I feel that I would be reinventing the wheel. So what did I do? I created a new rails application, and stripped it down, removing everything that is not needed to run the migrations.

    First, I created a rails application called ‘deploy’ on the root folder of the application with:

    rails new deploy
    

    Then, I removed all the…

    Continue Reading →

  • Rails 3.1 - will_paginate and AJAX

    November 10, 2011


    This post was originally published in the Rambling Labs Blog on November 10, 2011.


    For a project that I’m currently working on, I have a couple of list views that needed pagination. So I went with the ol’ will_paginate gem (which I first saw years ago when I didn’t even consider myself a developer) to take care of this.

    It’s as simple as including a line with gem 'will_paginate' on your Gemfile, running bundle install, and include this in the controller:

    class OrdersController < ApplicationController
      def index
        @orders = Order.paginate(page: params[:page], per_page: 10)
      end
    end
    

    And this in the view orders/index.html.erb:

    <div id="orders">
      <ul>
        <% @orders.each do |order| %>
          <li>
              <!-- Show order stuff -->

    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 →

  • Using Postgresql with Rails 3.1: the 'pg' gem

    October 17, 2011


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


    As you may know I’ve been learning Ruby on Rails for the last few weeks. I’m also currently developing an application using the edge version of RefineryCMS (which is really a Rails 3.1 application), integrated with the almighty Heroku.

    I wanted to use RefineryCMS with Postgresql, so the only thing that I had to do was installing postgresql and it’s corresponding gem ‘pg’… Or so I thought.

    I wasn’t surprised. About a year ago I had the same unfulfilled expectations with mysql and the mysql gem. So, this is what I had to do:

    • First, of course, install postgresql with apt-get install postgresql
    • Then, install the libpq-dev with apt-get install libpq-dev. Note…

    Continue Reading →