Sha256: b1cbecba7999f6d47f7176a12b8674a40271def8994ebd219236802ad88b4f25

Contents?: true

Size: 939 Bytes

Versions: 3

Compression:

Stored size: 939 Bytes

Contents

module X
  module Editable
    module Rails
      module ViewHelpers  
        def editable model, object, method, options = {}
          if can? :edit, model and xeditable?
            model_param = model.to_s.downcase.gsub('::', '_')
            model_name = model.to_s.downcase.gsub('::', '/')
            data_url = options[:nested_model] ? polymorphic_path([options[:nested_model], object]) : polymorphic_path(object)     
            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' => t("activerecord.attributes.#{model_name}#{"/#{options[:nested].singularize}" if options[:nested]}.#{method}") } do
                object.send(method) 
            end
          else
            options[:e]
          end
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
x-editable-rails-1.0.3 lib/x-editable-rails/view_helpers.rb
x-editable-rails-1.0.2 lib/x-editable-rails/view_helpers.rb
x-editable-rails-1.0.1 lib/x-editable-rails/view_helpers.rb