Class: ActionCrud::Helpers::Link
- Inherits:
-
Object
- Object
- ActionCrud::Helpers::Link
- Defined in:
- lib/action_crud/helpers/link.rb
Instance Attribute Summary collapse
-
#action ⇒ Object
Returns the value of attribute action.
-
#label ⇒ Object
Returns the value of attribute label.
-
#options ⇒ Object
Returns the value of attribute options.
-
#record ⇒ Object
Returns the value of attribute record.
Instance Method Summary collapse
-
#action_label ⇒ Object
Get link label.
-
#delete? ⇒ Boolean
Is delete action.
-
#initialize(context, record = nil, action = nil, *args) ⇒ Link
constructor
Initialize link generator.
-
#record_path ⇒ Object
Get record path.
-
#render ⇒ Object
Render link.
-
#render_multiple(*args) ⇒ Object
Render multiple.
Constructor Details
#initialize(context, record = nil, action = nil, *args) ⇒ Link
Initialize link generator
7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/action_crud/helpers/link.rb', line 7 def initialize(context, record=nil, action=nil, *args) = args. @context = context @record = record || @context.try(:current_record) @action = action @label = .fetch :label, nil = .except :label if delete? .reverse_merge!(method: :delete, data: { confirm: 'Are you sure?' }) end end |
Instance Attribute Details
#action ⇒ Object
Returns the value of attribute action.
4 5 6 |
# File 'lib/action_crud/helpers/link.rb', line 4 def action @action end |
#label ⇒ Object
Returns the value of attribute label.
4 5 6 |
# File 'lib/action_crud/helpers/link.rb', line 4 def label @label end |
#options ⇒ Object
Returns the value of attribute options.
4 5 6 |
# File 'lib/action_crud/helpers/link.rb', line 4 def end |
#record ⇒ Object
Returns the value of attribute record.
4 5 6 |
# File 'lib/action_crud/helpers/link.rb', line 4 def record @record end |
Instance Method Details
#action_label ⇒ Object
Get link label
26 27 28 |
# File 'lib/action_crud/helpers/link.rb', line 26 def action_label label || "#{action}".humanize end |
#delete? ⇒ Boolean
Is delete action
21 22 23 |
# File 'lib/action_crud/helpers/link.rb', line 21 def delete? action.in? [:delete, :destroy] end |
#record_path ⇒ Object
Get record path
31 32 33 |
# File 'lib/action_crud/helpers/link.rb', line 31 def record_path ActionCrud::Helpers::Route.new(@context, record, action).path || "#{action}" end |
#render ⇒ Object
Render link
49 50 51 |
# File 'lib/action_crud/helpers/link.rb', line 49 def render @context.link_to action_label, record_path, if record_path.present? end |
#render_multiple(*args) ⇒ Object
Render multiple
36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/action_crud/helpers/link.rb', line 36 def render_multiple(*args) default = = args. actions = args.concat(action).concat(.keys) links = actions.uniq.map do |item| args = Hash([item]).reverse_merge(default) ActionCrud::Helpers::Link.new(@context, record, item, args).render end links.join.html_safe end |