Sha256: caa307b158aed87a30d97b1527a2e22399087ff7c6295148b45a62ee33d6ce83

Contents?: true

Size: 1.06 KB

Versions: 1

Compression:

Stored size: 1.06 KB

Contents

module X
  module Editable
    module Rails
      module ViewHelpers  
        def editable object, method, options = {}
          data_url = polymorphic_path(object)
          object = object.last if object.kind_of?(Array)
          if can? :edit, object and xeditable?
            model = object.class.to_s.downcase
            model_param = model.gsub('::', '_')
            model_name = model.gsub('::', '/')
            klass = options[:nested] ? object.class.const_get(options[:nested].to_s.singularize.capitalize) : object.class
            content_tag :a, href: "#", class: "editable",
            data: { 
              type: 'text', 
              model: model_param, 
              name: method, 
              url: data_url, 
              nested: (options[:nested] if options[:nested]), 
              nid: (options[:nid] if options[:nid]), 
              :'original-title' => klass.human_attribute_name(method)
            } do
                object.send(method) 
            end
          else
            options[:e]
          end
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
x-editable-rails-1.2.2 lib/x-editable-rails/view_helpers.rb