Project

tila

0.0
No commit activity in last 3 years
No release in over 3 years
Provides a composition based approach to standard resource controllers
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

~> 4.2.5
 Project Readme

Tila

Tila is a set of modules that help you create simple CRUD controllers in Rails with very little code.

Gem Version

Most Rails projects contain a lot of controllers that are quite repetitive, because those controllers essentially implement what is needed to get a simple CRUD interface. This project contains components that can be used to build the controller of this simple CRUD interface.

Because Tila favors composition over inheritance, is allows for a flexibility that most other projects in this space don't have. If you only want to use a part of Tila, that works perfectly fine.

Installation

Include Tila in your project by adding it to your Gemfile.

gem 'tila'

Then run

bundle install

to make sure Tila is installed.

Usage

After Tila is installed in your project, you can use it like this.

class BunniesController < ApplicationController
  include Tila::Resourceful

  protected

  def permitted_resource_params
    resource_params.permit(:name, :fluffiness)
  end
end

This controllers will implement the basic CRUD actions (index, show, edit, update, new and create) for the Bunny model. You only need to specify the permitted_resource_params method to make sure only the expected parameters are passed into the resource. And you'll need to write your own views. Tila will automatically infer from the name of the controller class that this is a controller for the Bunny model and will make sure you can use @bunnies in the index view and @bunny in the other views.

Components

Tila favors composition of inheritance, so it contains a lot of small modules that can be used indepently. The example above only shows the result of including the Tila::Resourceful module, but you can choose to only include small parts of Tila. Below you can find a list of the components of Tila, with a short explanation of what they do and which other components they depend on.

  • Actionable: Provides an action helper so we can simply find out which action is called and contains a list of actions that are operated on collection and which actions are actions that save the model instance. It also provides simple helpers to find out if the current action is in one of the lists.
  • Modelable: Provides an model helper so we can access the model that the controller is for, and a few helpers to access model name.
  • Messages: Provide a simple helper for generating message strings from I18n. Requires Modelable.
  • Objects: Provides a simple accessor for @object and @objects. The ResourceLoaders component registers the loaded resources here.
  • Params: Provides a way to update the attributes of the object and simple starting point for filtering out the permitted resource params. Requires Modelable, Objects.
  • SaveDestroy: Provides the save_object and destroy_object methods. Requires Objects.
  • FormHandler: Provides methods to handle the submit of forms and the destroy. Requires Messages, Objects, SaveDestroy. You need to define a location_after_save and a location_after_destroy method, if you want to use this module in isolation. The Resourceful component defines these methods for you.
  • ResourceLoaders: Provides methods for loading the resources. Requires Modelable and Objects.
  • ResourcefulUrls: Generates the URLs to the controller. Requires Modelable.
  • Resourceful: Implements the actual controller actions, registers the before_action to load the resources. This is the part that you want to include when you want to enjoy the full glory of Tila. Requires Actionable, Params, FormHandler, ResourceLoaders and ResourcefulUrls.