Skip to content
This repository has been archived by the owner on Feb 7, 2020. It is now read-only.

Generic Views

botanicus edited this page Sep 13, 2010 · 13 revisions

This page is up to date for Rango HEAD. The API was changed since 0.1, where everything was happening in Rango::GV module.

Introduction

If you have some repetitive tasks which can be shared across more controllers, you can use generic views to handle them. Classical example is when you just want to render a template. There is quite common that guys just have bunch of methods which do just render. This is bad practice, and thanks to generic views, the only thing you have to do is route some URL to Rango::GV.static.

This is how generic views works in Django. But in Rango, you can do more. You can for example include Rango::GV in your controller and then use filters or even super to extend the view.

Basic Usage

Usage in Context of Controllers

Example with Filters

And then you can use Static.dispatcher(:static) with your customized version of static view.

Example with Inheritance

As in the first example, just use Static.dispatcher(:static) instead of Rango::GV.static in your router.

How to Write a Generic View

Easy, right? In the block you can access to request, use render etc, it’s basically very similar to Rango::Controller, but it’s more lightweight. If you need to customize it more, with filters for example, just include it into your controller as showed in example above.