Rails matching PHP

At first the problem: After the VegiKochbuch relaunch as Rails project I realized that all old links to recipes are broken and this causes a lot of 404 errors.

The old PHP link structure was: http://vegikochbuch.de/rezepte/rezept175.php
And now in Rails it’s: http://vegikochbuch.de/recipes/175

My solution was adding

match '/rezepte/rezept:id.php' => 'recipes#show'

to routes.rb

It works and is realy simple. I don’t really know if this is the best way, but I like it!

 

My Rails project: Static pages

How to create static pages, for example legal notice, on a Rails project.

1. Step: The Controller

./script/rails generate controller Static

The controller code:

class StaticController < ApplicationController
  def method_missing(name)
    render :template => "static/#{name}"
  end
end

2. Step: Routes

In your config/routes.rb add one line for every static page:

match 'legal_notice' => 'static#legal_notice'

3. Step: The view

Create a new directory app/views/static and add your page legal_notice.html.haml

Now go to http://your-application.com/legal_notice – that’s all.