app/helpers/link_helper.rb in udongo-6.2.1 vs app/helpers/link_helper.rb in udongo-6.3.0
- old
+ new
@@ -5,10 +5,21 @@
path_from_string_or_object(value),
title: t('b.view')
)
end
+ # Say you have a page with a title: 'Foo'. When calling this method with that
+ # page object, you would get a link to /backend/pages/edit/1 with the title
+ # as label.
+ def link_to_edit_with_label(value, locale)
+ link_to(
+ object_label(value, locale),
+ path_from_string_or_object(value, 'edit_'),
+ title: t('b.edit')
+ )
+ end
+
def link_to_edit(value)
link_to(
icon(:pencil_square_o),
path_from_string_or_object(value, 'edit_'),
title: t('b.edit')
@@ -30,14 +41,25 @@
data: { confirm: t('b.msg.confirm') },
title: t('b.delete')
)
end
- private
-
def path_from_string_or_object(value, prefix = nil)
return value if value.is_a?(String)
str = "#{prefix}#{Udongo::ObjectPath.find(value)}"
send(str, *Udongo::ObjectPath.remove_symbols(value))
+ end
+
+ def object_label(value, locale)
+ obj = Udongo::ObjectPath.remove_symbols(value)
+ obj = obj.last if obj.is_a?(Array)
+
+ I18n.with_locale(locale) do
+ return obj.title if obj.respond_to?(:title)
+ return obj.name if obj.respond_to?(:name)
+ return obj.description if obj.respond_to?(:description)
+ end
+
+ "#{I18n.t("b.#{obj.class.name.underscore}")}: #{obj.id}"
end
end