Coder Social home page Coder Social logo

tila's Introduction

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.

tila's People

Contributors

rolfvandekrol avatar

Watchers

Marthyn Olthof avatar James Cloos avatar Robert Vermeulen avatar Menno Dragt avatar Giuseppe Maggiore avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.