Sha256: 9cd1923d909367478d8ae231a64c2a9d8c5e969d165aa3fad863f6b6e73149fb
Contents?: true
Size: 979 Bytes
Versions: 3
Compression:
Stored size: 979 Bytes
Contents
module Viewable module Field module Url extend ActiveSupport::Concern included do before_update :normalize_url after_commit :reload_routes scope :with_url, -> { where("url LIKE '/%'") } end class_methods do def names "Naming::#{name}".constantize.names end def urls localized.with_url.pluck(:url) end def all_urls paths = names.map do |name| Rails.application.routes.url_helpers.try "#{name}_path" end.compact (paths + urls).sort.uniq end end private def normalize_url if url.present? segments = url.split('/').reject(&:blank?) segments.map{ |segment| segment.to_slug.normalize.to_s } self.url = segments.join('/').prepend('/') end end def reload_routes Rails.application.routes_reloader.reload! end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
rails_admin_cms-0.1.1 | app/models/viewable/field/url.rb |
rails_admin_cms-0.0.9 | app/models/viewable/field/url.rb |
rails_admin_cms-0.0.7 | app/models/viewable/field/url.rb |