GithubHelp home page GithubHelp logo

controller_less's Introduction

ControllerLess

ControllerLess is DSL to DRY controller and Routes using inherited_resources inspired by activeadmin.

Installation

ControllerLess requires ruby 2.* with rails 3.-4. to run.

gem 'controller_less', '~> 0.0.9.pre'

Basic Usage

Initialize the gem by creating file in config/initializers/controller_less.rb, the basic file will look like this.

ControllerLess.setup do
end

You will also need to add this line ControllerLess.load_routes in config/routes.rb.

To use ControllerLess you have to create posts_cls.rb in the app/cls folder.

ControllerLess.register Post do
end

Namespace

To use namespace pass the parameter of namespace to .register method checkbelow for example.

Controller.register Post, namespace: "Api::V1" do
end

Restricting the Routes and Action Created

By default ControllerLess creates seven actions with their routes using inherited_resources. You can restrict the access by passing options to only method. check the exmaple below

Controller.register Post do
    only :index, :show
end

Callbacks

Following methods are delegate to controller.

:respond_to, :_insert_callbacks, :_normalize_callback_options, :after_action, :append_after_action, :append_around_action, :append_before_action, :around_action, :before_action, :prepend_after_action, :prepend_around_action, :prepend_before_action, :skip_action_callback, :skip_after_action, :skip_around_action, :skip_before_action, :skip_filter

How to use the callback in ControllerLess check the example below.

ControllerLess.register User do
    before_action :authenticate_user! 
end

Strong Parameters

ControllerLess works smooth with Strong Parameters to allow the parameters pass the values to permitted_params. Please check the example below.

ControllerLess.register Post do
    permitted_params :title, :create
end

Overriding methods & Add Private methods

You can override method by writing code in controller block. Please the check the example.

ControllerLess.register Post do
    controller do
        def index
            @posts = Post.last(5)
        end
    end
end

Bugs and Feedback

If you discover any bug please report it in the issue tracker. Feedback can be sent to a2ninek [at] yahoo [dot] com. MIT License. Copyright (c) 2015-2017 Kamal Ejaz.

controller_less's People

Contributors

victorcreed avatar

Stargazers

 avatar  avatar Waleed Arshad avatar Imran Latif avatar

Watchers

James Cloos avatar  avatar  avatar

Forkers

waleedarshad-vf

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.