0
votes

I'm currently learning Rails and it's awesome but I really like Symfony's routing system. In Symfony it is possible to define routes directly in Controller with annotations. For example:

/**
 * @Route("/blog")
 */
class PostController extends Controller
{
    /**
     * @Route("/{id}")
     */
    public function showAction($id)
    {
    }
}

This means that /blog/5 will route to PostController#showAction. I like this approach because routes are defined directly before your action method and, from my point of view, it makes more sense than defining everything in a single file.

Is there something similar for Rails?

Thank you!

1

1 Answers

3
votes

No, there is nothing similar to this for Rails. With Rails, you must define the routes in config/routes.rb and have the controller actions separate. You could then put comments on the actions declaring what routes go to it, but most people don't do this.

If it really bothers you, you could use Sinatra which doesn't even have the concept of controllers. Instead, you define methods like this:

get '/' do
  "Hello world"
end

Any GET request going to / will show "Hello World" on the screen.

Sinatra is something that I would personally only use for featherweight applications, dipping into other things like Padrino or Rails for anything heavier.