RailsRouteBuilder

RailsRouteBuilder

new RailsRouteBuilder()

RailsRanger object constructor

Source:

Methods

create(resource, params) → {Promise}

Returns a path and params to the create action of a given resource

Source:
Parameters:
Name Type Description
resource string

A resource name

params object

Any parameters for the request

Returns:
Type:
Promise
Example
const routes = new RailsRouteBuilder
routes.create('users', { email: 'john@doe.com' })
//=> { path: '/users', params: { email: 'john@doe.com' } }

destroy(resource, params) → {Promise}

Returns a path and params to the destroy action of a given resource

Source:
Parameters:
Name Type Description
resource string

A resource name

params object

Any parameters for the request

Name Type Description
id number | string

The id of the resource

Returns:
Type:
Promise
Example
const routes = new RailsRouteBuilder
routes.destroy('users', { id: 1 })
//=> { path: '/users/1', params: {} }

edit(resource, params) → {Promise}

Returns a path and params to the edit action of a given resource

Source:
Parameters:
Name Type Description
resource string

A resource name

params object

Any parameters for the request

Name Type Description
id number | string

The id of the resource

Returns:
Type:
Promise
Example
const routes = new RailsRouteBuilder
routes.edit('users', { id: 1 })
//=> { path: '/users/1', params: {} }

index(resource, params) → {Promise}

Returns a path and params to the index action of a given resource

Source:
Parameters:
Name Type Description
resource string

A resource name

params object

Any parameters for the request

Returns:
Type:
Promise
Example
const routes = new RailsRouteBuilder
routes.index('users')
//=> { path: '/users', params: {} }

list()

An alias for the RailsRouteBuilder#index function

Source:

namespace(namespace, params)

Defines a namespace to be used in the next route of the chain

Source:
Parameters:
Name Type Description
namespace string

The path fragment to be used as the namespace

params object

The parameters to be interpolated into the path, can be left empty

Example
const routes = new RailsRouteBuilder
routes.namespace('admin').list('blogPosts')
//=> { path: '/admin/blog_posts', params: {} }

new(resource, params) → {Promise}

Returns a path and params to the new action of a given resource

Source:
Parameters:
Name Type Description
resource string

A resource name

params object

Any parameters for the request

Returns:
Type:
Promise
Example
const routes = new RailsRouteBuilder
routes.new('users')
//=> { path: '/users', params: {} }

resource(resource, id)

Defines a namespace to be used in the next route of the chain

Source:
Parameters:
Name Type Default Description
resource string

the name of the resource to be used as namespace

id integer null

the ID of the resource, can be left empty

Example
const routes = new RailsRouteBuilder
routes.resource('users', 1).list('blogPosts')
//=> { path: '/users/1/blog_posts', params: {} }

show(resource, params) → {Promise}

Returns a path and params to the show action of a given resource

Source:
Parameters:
Name Type Description
resource string

A resource name

params object

Any parameters for the request

Name Type Description
id number | string

The id of the resource

Returns:
Type:
Promise
Example
const routes = new RailsRouteBuilder
routes.show('users', { id: 1 })
//=> { path: '/users/1', params: {} }

update(resource, params) → {Promise}

Returns a path and params to the update action of a given resource

Source:
Parameters:
Name Type Description
resource string

A resource name

params object

Any parameters for the request

Name Type Description
id number | string

The id of the resource

Returns:
Type:
Promise
Example
const routes = new RailsRouteBuilder
routes.update('users', { id: 1, email: 'john@doe.com' })
//=> { path: '/users/1', params: { email: 'john@doe.com' } }