Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
best_in_place_mongoid
Advanced tools
##Description
Best in Place Mongoid is a fork of Best in Place prepared for Mongoid documents. Best in place jQuery based AJAX Inplace-Editor that takes profit of RESTful server-side controllers to allow users to edit stuff with no need of forms. If the server have standard defined REST methods, particularly those to UPDATE your objects (HTTP PUT), then by adding the Javascript file to the application it is making all the fields with the proper defined classes to become user in-place editable.
The editor works by PUTting the updated value to the server and GETting the updated record afterwards to display the updated value.
##Features
##Usage of Rails 3 Gem
best_in_place object, field, OPTIONS
Params:
Options:
Examples (code in the views):
<%= best_in_place @user, :name, :type => :input %>
<%= best_in_place @user, :name, :type => :input, :nil => "Click me to add content!" %>
<%= best_in_place @user, :description, :type => :textarea %>
<%= best_in_place @user, :country, :type => :select, :collection => [[1, "Spain"], [2, "Italy"], [3, "Germany"], [4, "France"]] %>
Of course it can take an instance or global variable for the collection, just remember the structure [[key, value], [key, value],...]. The key can be a string or an integer.
<%= best_in_place @user, :receive_emails, :type => :checkbox, :collection => ["No, thanks", "Yes, of course!"] %>
The first value is always the negative boolean value and the second the positive. Structure: ["false value", "true value"]. If not defined, it will default to Yes and No options.
If you are using a Rails application, your controller's should respond to json in case of error. Example:
def update
@user = User.find(params[:id])
respond_to do |format|
if @user.update_attributes(params[:user])
format.html { redirect_to(@user, :notice => 'User was successfully updated.') }
format.json { head :ok }
else
format.html { render :action => "edit" }
format.json { render :json => @user.errors.full_messages, :status => :unprocessable_entity }
end
end
end
At the same time, you must define the restrictions, validations and error messages in the model, as the example below:
When the user tries to introduce invalid data, the error messages defined in the model will be displayed in pop-up windows using the jQuery.purr plugin.
##Installation
It works by simply copying and loading the files from the folder /public/javascripts to your application and loading them in your layouts in the following order:
The last one you can copy it (and keeping up to date to the last version) by running the following generator in your application's root. Remember to do it every time you update the gem (or you will see no change).
rails g best_in_place:setup
To be able to use the script the following block must be added as well:
$(document).ready(function() {
/* Activating Best In Place */
jQuery(".best_in_place").best_in_place()
});
In order to use the Rails 3 gem, just add the following line to the gemfile:
gem "best_in_place"
If the script is used with the Rails Gem no html tags will be allowed unless the sanitize option is set to true, in that case only the tags [b i u s a strong em p h1 h2 h3 h4 h5 ul li ol hr pre span img] will be allowed. If the script is used without the gem and with frameworks other than Rails, then you should make sure you are providing the csrf authenticity params as meta tags and you should always escape undesired html tags such as script, object and so forth.
<meta name="csrf-param" content="authenticity_token"/>
<meta name="csrf-token" content="YOUR UNIQUE TOKEN HERE"/>
##TODO
##Changelog
##Authors, License and Stuff
Code by Bernat Farrero from Itnig Web Services (it was based on the original project of Jan Varwig) and released under MIT license.
Many thanks to the contributors: Roger Campos and Jack Senechal
FAQs
Unknown package
We found that best_in_place_mongoid demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.