Sha256: f7ecd805a919bd93d296377edad082b95bb900953fb36c39f0370cae42a989be

Contents?: true

Size: 1.01 KB

Versions: 2

Compression:

Stored size: 1.01 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('::', '_')
            klass = options[:nested] ? object.class.const_get(options[:nested].to_s.singularize.capitalize) : object.class
            content_tag :a, href: '#', class: 'editable', title: options.fetch(:title, klass.human_attribute_name(method)),
            data: { 
              type: options.fetch(:type, 'text'), 
              model: model_param, 
              name: method, 
              url: data_url, 
              nested: options[:nested], 
              nid: options[:nid]
            } do
                object.send(method).try(:html_safe)
            end
          else
            options[:e]
          end
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
x-editable-rails-1.4.0 lib/x-editable-rails/view_helpers.rb
x-editable-rails-1.3.0 lib/x-editable-rails/view_helpers.rb