Articles tagged 'rails'

  • Writing your blog posts in Markdown with Postmarkdown

    February 3, 2012


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


    Another thing we added to our new site, uploaded back at the end of December, was the ability to write our blog posts in Markdown, which is a text-to-html tool that allows you to write formatted text without actually having to write all the corresponding HTML. Markdown is used for the project wiki pages on GitHub, and can also be used for the project’s readme file.

    Most of the time, I don’t like that HTML gets autogenerated for me, since I usually don’t get the results I want. We used to have the site (which was really the blog only) in WordPress, and I never used the autogenerated HTML. In fact, it was quite the opposite: I wrote every blog post in plain…

    Continue Reading →

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

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