diff --git a/README.md b/README.md index d0116bed..0d8251ab 100644 --- a/README.md +++ b/README.md @@ -77,6 +77,7 @@ Options: - **:as** It can be only [:input, :textarea, :select, :checkbox, :date] or if undefined it defaults to :input. - **:collection**: If you are using the :select type then you must specify the collection of values it takes as a hash where values represent the display text and keys are the option's value when selected. If you are using the :checkbox type you can specify the two values it can take, or otherwise they will default to Yes and No. - **:url**: URL to which the updating action will be sent. If not defined it defaults to the :object path. +- **:method**: HTTP method to be used for the request. Defaults to :put - **:place_holder**: The nil param defines the content displayed in case no value is defined for that field. It can be something like "click me to edit". If not defined it will show *"-"*. - **:activator**: Is the DOM object that can activate the field. If not defined the user will making editable by clicking on it. diff --git a/lib/assets/javascripts/best_in_place.js b/lib/assets/javascripts/best_in_place.js index db3f8bde..f77c761c 100644 --- a/lib/assets/javascripts/best_in_place.js +++ b/lib/assets/javascripts/best_in_place.js @@ -103,7 +103,7 @@ BestInPlaceEditor.prototype = { } editor.ajax({ - "type": BestInPlaceEditor.defaults.ajaxMethod, + "type": this.ajaxMethod, "dataType": BestInPlaceEditor.defaults.ajaxDataType, "data": editor.requestData(), "success": function (data, status, xhr) { @@ -169,6 +169,7 @@ BestInPlaceEditor.prototype = { self.element.parents().each(function () { var $parent = jQuery(this); self.url = self.url || $parent.data("bipUrl"); + self.ajaxMethod = self.ajaxMethod || $parent.data("bipMethod"); self.activator = self.activator || $parent.data("bipActivator"); self.okButton = self.okButton || $parent.data("bipOkButton"); self.okButtonClass = self.okButtonClass || $parent.data("bipOkButtonClass"); @@ -179,6 +180,7 @@ BestInPlaceEditor.prototype = { // Load own attributes (overrides all others) self.url = self.element.data("bipUrl") || self.url || document.location.pathname; + self.ajaxMethod = self.element.data("bipMethod") || BestInPlaceEditor.defaults.ajaxMethod; self.collection = self.element.data("bipCollection") || self.collection; self.formType = self.element.data("bipType") || "input"; self.objectName = self.element.data("bipObject") || self.objectName; @@ -253,7 +255,7 @@ BestInPlaceEditor.prototype = { var csrf_token = jQuery('meta[name=csrf-token]').attr('content'), csrf_param = jQuery('meta[name=csrf-param]').attr('content'); - var data = "_method=" + BestInPlaceEditor.defaults.ajaxMethod; + var data = "_method=" + this.ajaxMethod; data += "&" + this.objectName + '[' + this.attributeName + ']=' + encodeURIComponent(this.getValue()); if (csrf_param !== undefined && csrf_token !== undefined) { diff --git a/lib/best_in_place/helper.rb b/lib/best_in_place/helper.rb index 74d5e6e7..9db790c9 100644 --- a/lib/best_in_place/helper.rb +++ b/lib/best_in_place/helper.rb @@ -49,6 +49,7 @@ def best_in_place(object, field, opts = {}) options[:data]['bip-skip-blur'] = opts.has_key?(:skip_blur) ? opts[:skip_blur].presence : BestInPlace.skip_blur options[:data]['bip-url'] = url_for(opts[:url] || object) + options[:data]['bip-method'] = opts[:method] unless opts[:method].blank? options[:data]['bip-confirm'] = opts[:confirm].presence options[:data]['bip-value'] = html_escape(value).presence