Project

rails-dsl

0.0
No commit activity in last 3 years
No release in over 3 years
Provide Rails with some extra tools, please read README.md on git
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 0

Runtime

>= 3.0.0
>= 1.6.0
 Project Readme

rails-dsl

Provide Rails with some extra helpers,

Terminal

if you call rails with 'kill' / 'k' command from now on, it will kill the application by it's pid file

$ rails kill
#> At pid: 24922 the app is killed with pidfile: /home/asdf/rails_app/tmp/pids/server.pid

Routing

Mount controller

As pages
  • mount a controller public methods as routes.
  • the method name will be the path
    #> controller
    class PagesController < ApplicationController

      def test

      end

    end

    #> routes.rb

    RailsApp::Application.routes.draw do
      mount_by class: :pages || PageController
    end
As API behavor
  • arguments will be parsed into route :params so the othere side can cache based on url

    • the method actually receive the passed parameter so you can use like in the example
  • by extend the method name you can set the methods REST method by the followind endings or beginnings:

    • get || get
    • post || post
    • put || put
    • delete || delete
    #> controller
    class PagesController < ApplicationController

      #> this generate /test1/:hello.:format  path
      def test1 hello
        {hello: hello }
      end

      #> this generate /test2.:format  path
      def test2
        {hello: 'hello' }
      end

      #> POST /test.:format -> default json
      def test2_post
        {hello: 'blabla' }
      end

    end

    #> routes.rb
    RailsApp::Application.routes.draw do

      # you can still use the Class name too
      mount_by class: :pages

      # defaults can be passed 
      mount_by class: :pages, defaults: { format: :xml }

    end