diff options
| author | Teddy Wing | 2017-09-01 14:47:29 +0200 |
|---|---|---|
| committer | Teddy Wing | 2017-09-01 14:47:29 +0200 |
| commit | 9574d8b8351fd59eeada05a1ba71893a82b86989 (patch) | |
| tree | 96fc2696e09c85063741ce3a71f44f800d11f127 /app | |
| parent | d127ed12158550f84ef1fb9c21d6360c86ac3642 (diff) | |
| download | chouette-core-9574d8b8351fd59eeada05a1ba71893a82b86989.tar.bz2 | |
TableBuilderHelper::Column: Add `link_to` argument
This parameter will be used as the `href` to link the column value
somewhere.
We give it a lambda because this makes it easier to call any method on
the row object.
This means the accessor needs to take the object as an argument, like in
the `#value` method, because we don't have a better way to handle that
(it can't be done at initialisation time because at that point we don't
have row objects, we have a collection).
Diffstat (limited to 'app')
| -rw-r--r-- | app/helpers/table_builder_helper/column.rb | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/app/helpers/table_builder_helper/column.rb b/app/helpers/table_builder_helper/column.rb index 800a8282e..ef3c0b629 100644 --- a/app/helpers/table_builder_helper/column.rb +++ b/app/helpers/table_builder_helper/column.rb @@ -2,7 +2,7 @@ module TableBuilderHelper class Column attr_reader :key, :name, :attribute, :sortable - def initialize(key: nil, name: '', attribute:, sortable: true) + def initialize(key: nil, name: '', attribute:, sortable: true, link_to: nil) if key.nil? && name.empty? raise ColumnMustHaveKeyOrNameError end @@ -11,6 +11,7 @@ module TableBuilderHelper @name = name @attribute = attribute @sortable = sortable + @link_to = link_to end def value(obj) @@ -29,6 +30,10 @@ module TableBuilderHelper I18n.t("activerecord.attributes.#{model_key}.#{@key}") end + + def link_to(obj) + @link_to.call(obj) + end end |
