0.0
No commit activity in last 3 years
No release in over 3 years
Power up RESTful resources!
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.6
~> 2.3.0
~> 10.1.0
~> 2.14.0
~> 1.3.9

Runtime

~> 4.1.1
~> 4.1.1
 Project Readme

PowerResource

Power up RESTful resources!

Requirements

  • Ruby 2.1 or greater
  • Rails 4.1 or greater
  • Active Record 4.1 or greater

Installation

Add this line to your application's Gemfile:

gem 'power_resource'

And then execute:

$ bundle

Or install it yourself as:

$ gem install power_resource

Usage

Basic Usage

Inherit your resource controllers from PowerResource::BaseController:

class PostsController < PowerResource::BaseController
end

Strong Parameters

Permit only title and content (recommended way):

class PostsController < PowerResource::BaseController
  def permit_attributes
    %w(title content)
  end
end

Permit all attributes:

class PostsController < PowerResource::BaseController
  def permit_attributes
    resource_attributes
  end
end

Permit all attributes except id:

class PostsController < PowerResource::BaseController
  def permit_attributes
    resource_attributes - %w(id)
  end
end

Permit all human-readable attributes (all except id, created_at and updated_at):

class PostsController < PowerResource::BaseController
  def permit_attributes
    resource_human_attributes
  end
end

Permit all human-readable attributes, except title and content:

class PostsController < PowerResource::BaseController
  def permit_attributes
    resource_human_attributes - %w(title content)
  end
end

Setting default behaviour can be done in ApplicationController:

class ApplicationController < ActionController::Base
  def permit_attributes
    resource_human_attributes
  end
end

Also, you can use Inherited Resources way way:

class PostsController < PowerResource::BaseController
  def permitted_params
    params.permit(post: %w(title content))
  end
end

Helpers

Besides all helpers from Inherited Resources gem, next helper methods are available:

resource_form_path   #=> /products     when creating a new resource
                     #=> /products/1   when resource already exists

Support

If you have any questions or issues with PowerResource, or if you like to report a bug, please create an issue on GitHub.

License

MIT License. Copyright (c) 2013 - 2014 Jari Jokinen. See LICENSE for further details.