Module: Weeler::ActionController::Acts::Restful::ClassMethods

Defined in:
lib/weeler/action_controller/acts/restful.rb

Instance Method Summary collapse

Instance Method Details

#acts_as_restful(active_record_model, options = {}) ⇒ Object

Weeler action controller method. It creates all restful actions for action controller. Create a controller for your model (e.g. Post) what you want to administrate in weeler. Add method acts_as_restful Post and permit params for your resource - option permit_params. Also you can paginate - add option paginate e.g.

class Weeler::PostController < Weeler::ContentController
  acts_as_restful Post, permit_params: [:title, :body], paginate: 50
end

It will handle :index, :new, :edit, :update, :destroy, :order, :activation and :remove_image actions

For permiting custom by role or permiting all params (permit!), you must add block permit_params: -> (params) { params.require(:post).permit! }

You should implement form file with your own active record attributes. To do that, create _form.html.haml in views/weeler/YOUR_RESOURCE/_form.html.haml where YOUR_RESOURCE is name of your resource.

Also you can override all standart restful action view and implement, if you need, _filter.html.haml



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/weeler/action_controller/acts/restful.rb', line 32

def acts_as_restful(active_record_model, options = {})
  before_action(:load_record, only: [:show, :edit, :update, :destroy, :remove_image])

  include InstanceMethodsOnActivation
  helper_method :item_humanized_name

  cattr_accessor :model do
    active_record_model
  end

  cattr_accessor :permited_params do
    options[:permit_params] if options.include? :permit_params
  end

  cattr_accessor :paginate do
    options[:paginate] if options.include? :paginate
  end

  cattr_accessor :order_by do
    options[:order_by] if options.include? :order_by
  end
end