Sha256: 13b2ab2727e2b865340238c0c69c7717e85bd5d1218478df43d9ec85e24ebd50

Contents?: true

Size: 1.15 KB

Versions: 6

Compression:

Stored size: 1.15 KB

Contents

module Admin
  module ResourcesHelper
    def resolve_field(resource,list_field_item)
      resolved = list_field_item.class.to_s
      case list_field_item
      when Symbol,String
        val = resource.send(list_field_item)
        case val
        when ActiveSupport::TimeWithZone
          resolved =l(val,format: :long)
        else
          resolved = val
        end
      when Hash
        rel = resource.send(list_field_item.first.first)
        resolved = rel.send(list_field_item.first.last)
      end
      resolved
    end
    def resolve_field_name(list_field_item)
      case list_field_item
      when Symbol,String
        resource_class.human_attribute_name(list_field_item)
      when Hash
        resource_class.human_attribute_name(list_field_item.first.first)
      end
    end

    def link_to_add_fields(name, f, type)
      new_object = f.object.send "build_#{type}"
      id = "new_#{type}"
      fields = f.send("#{type}_fields", new_object, child_index: id) do |builder|
        render(type.to_s + "_fields", f: builder)
      end
      link_to(name, '#', class: "add_fields", data: {id: id, fields: fields.gsub("\n", "")})
    end


    
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
unknown_admin-0.1.4 app/helpers/admin/resources_helper.rb
unknown_admin-0.1.3 app/helpers/admin/resources_helper.rb
unknown_admin-0.1.2 app/helpers/admin/resources_helper.rb
unknown_admin-0.1.1 app/helpers/admin/resources_helper.rb
unknown_admin-0.1.0 app/helpers/admin/resources_helper.rb
unknown_admin-0.0.1 app/helpers/admin/resources_helper.rb