module Zobi::Inherited
This module add some helpers to controllers.
* inherit_resources * params filtering
Public Class Methods
included(klass)
click to toggle source
# File lib/zobi/inherited.rb, line 10 def self.included(klass) klass.send 'include', Inherited::Hidden klass.send 'respond_to', :html end
Public Instance Methods
create() { |r| ... }
click to toggle source
# File lib/zobi/inherited.rb, line 21 def create r = zobi_resource_class.create permitted_params[zobi_resource_key] instance_variable_set "@#{resource_key}", r args = route_namespace args << r block_given? ? yield(r) : respond_with(*args) end
Also aliased as: create!
destroy() { |resource| ... }
click to toggle source
# File lib/zobi/inherited.rb, line 38 def destroy resource.destroy block_given? ? yield(resource) : redirect_to(collection_path) end
Also aliased as: destroy!
edit()
click to toggle source
# File lib/zobi/inherited.rb, line 18 def edit end
new()
click to toggle source
# File lib/zobi/inherited.rb, line 15 def new end
update() { |resource| ... }
click to toggle source
# File lib/zobi/inherited.rb, line 30 def update resource.update_attributes permitted_params[zobi_resource_key] args = route_namespace args << resource block_given? ? yield(resource) : respond_with(*args) end
Also aliased as: update!
Protected Instance Methods
resource()
click to toggle source
# File lib/zobi/inherited.rb, line 46 def resource r = instance_variable_get "@#{resource_key}" return r if r.present? instance_variable_set( "@#{resource_key}", (params[:id].present? ? resource_class.find(params[:id]) : resource_class.new ) ) return instance_variable_get "@#{resource_key}" end
route_namespace()
click to toggle source
# File lib/zobi/inherited.rb, line 59 def route_namespace self.class.name.split('::')[0...-1].map(&:downcase) end
Private Instance Methods
inherited_collection(c)
click to toggle source
# File lib/zobi/inherited.rb, line 65 def inherited_collection c c end