module Undercarriage::Controllers::ActionConcern

Action helpers

Helpers for the controller or view to help identify the action

Usage

class ExamplesController < ApplicationController
  include Undercarriage::Controllers::ActionConcern
end

Public Instance Methods

action?(action_method) click to toggle source

Check action

Check if action is a certain action type

Usage

action?(:show) # true
action?('show') # true
action?(:index) # false

@param action_method [String, Symbol] the action to test @return [Boolean] if action matches

# File lib/undercarriage/controllers/action_concern.rb, line 49
def action?(action_method)
  action == action_method.to_sym
end
collection_action?() click to toggle source

Check if collection

Check if action is a collection action type. An action is a collection type if it is the `index` action

Usage

collection_action? # true
collection_action? # false

@return [Boolean] if action is collection type

# File lib/undercarriage/controllers/action_concern.rb, line 169
def collection_action?
  collection_actions.include?(action)
end
create_action?() click to toggle source

Check if create

Check if action is the create action type. The check will pass if it is a `create` action

Usage

create_action? # true
create_action? # false

@return [Boolean] if action is action type

# File lib/undercarriage/controllers/action_concern.rb, line 109
def create_action?
  action?('create')
end
create_actions?() click to toggle source

Check if create or new

Check if action is a create or new action type. The check will pass if it is a `create` or `new` action

Usage

create_actions? # true
create_actions? # false

new_actions? # true
new_actions? # false

@return [Boolean] if action is actions type

# File lib/undercarriage/controllers/action_concern.rb, line 187
def create_actions?
  create_actions.include?(action)
end
Also aliased as: new_actions?
destroy_action?() click to toggle source

Check if destroy

Check if action is the destroy action type. The check will pass if it is a `destroy` action

Usage

destroy_action? # true
destroy_action? # false

@return [Boolean] if action is action type

# File lib/undercarriage/controllers/action_concern.rb, line 154
def destroy_action?
  action?('destroy')
end
edit_action?() click to toggle source

Check if edit

Check if action is the edit action type. The check will pass if it is an `edit` action

Usage

edit_action? # true
edit_action? # false

@return [Boolean] if action is action type

# File lib/undercarriage/controllers/action_concern.rb, line 124
def edit_action?
  action?('edit')
end
edit_actions?()
Alias for: update_actions?
index_action?() click to toggle source

Check if index

Check if action is the index action type. The check will pass if it is an `index` action

Usage

index_action? # true
index_action? # false

@return [Boolean] if action is action type

# File lib/undercarriage/controllers/action_concern.rb, line 64
def index_action?
  action?('index')
end
member_action?() click to toggle source

Check if member

Check if action is a member action type. An action is a member type if it is the `edit`, `show`, or `update` action

Usage

member_action? # true
member_action? # false

@return [Boolean] if action is member type

# File lib/undercarriage/controllers/action_concern.rb, line 204
def member_action?
  member_actions.include?(action)
end
new_action?() click to toggle source

Check if new

Check if action is the new action type. The check will pass if it is a `new` action

Usage

new_action? # true
new_action? # false

@return [Boolean] if action is action type

# File lib/undercarriage/controllers/action_concern.rb, line 94
def new_action?
  action?('new')
end
new_actions?()
Alias for: create_actions?
show_action?() click to toggle source

Check if show

Check if action is the show action type. The check will pass if it is a `show` action

Usage

show_action? # true
show_action? # false

@return [Boolean] if action is action type

# File lib/undercarriage/controllers/action_concern.rb, line 79
def show_action?
  action?('show')
end
update_action?() click to toggle source

Check if update

Check if action is the update action type. The check will pass if it is an `update` action

Usage

update_action? # true
update_action? # false

@return [Boolean] if action is action type

# File lib/undercarriage/controllers/action_concern.rb, line 139
def update_action?
  action?('update')
end
update_actions?() click to toggle source

Check if edit or update

Check if action is an edit or update action type. The check will pass if it is an `edit` or `update` action

Usage

update_actions? # true
update_actions? # false

edit_actions? # true
edit_actions? # false

@return [Boolean] if action is actions type

# File lib/undercarriage/controllers/action_concern.rb, line 222
def update_actions?
  update_actions.include?(action)
end
Also aliased as: edit_actions?

Protected Instance Methods

action() click to toggle source

Action symbol

Take `action_name` (string) and turn it into a symbol

# File lib/undercarriage/controllers/action_concern.rb, line 234
def action
  action_name.to_sym
end
collection_actions() click to toggle source

Collection actions

# File lib/undercarriage/controllers/action_concern.rb, line 241
def collection_actions
  %i[index]
end
create_actions() click to toggle source

Create actions

# File lib/undercarriage/controllers/action_concern.rb, line 255
def create_actions
  %i[create new]
end
member_actions() click to toggle source

Member actions

# File lib/undercarriage/controllers/action_concern.rb, line 248
def member_actions
  %i[edit show update]
end
update_actions() click to toggle source

Update actions

# File lib/undercarriage/controllers/action_concern.rb, line 262
def update_actions
  %i[edit update]
end