GitXplorerGitXplorer
a

jeditable-rails

public
34 stars
18 forks
11 issues

Commits

List of commits on branch master.
Unverified
bd07ab435ed49e0d7baf0fadb1dd157438ff8e21

added more detail around the update action response

aafeld committed 13 years ago
Unverified
03e60914bb589196287d56f367eed92126693b07

Merge pull request #14 from augustf/patch-1

aafeld committed 13 years ago
Unverified
7ae436c423b577bd1db476d9af2b25d6b1f4b43e

Updated README with controller code documentation mentioned in Issue #9

committed 13 years ago
Unverified
98f757bcc3f6ee331c4904adf10983258f45e688

run dummy app migrations for specs

aafeld committed 14 years ago
Unverified
f7247b5cec35aa139ed672d35eb0d86d3a53b016

use Gadget scaffold in dummy app for specs

aafeld committed 14 years ago
Unverified
3c86aa80231ac470b8a9b9b4214646bc723ed899

converted README to markdown, and added Travis build status icon

aafeld committed 14 years ago

README

The README file for this repository.

jeditable-rails Build Status

A gem to add in-place-editable fields to your Rails project. It is a wrapper for the Jeditable jQuery plugin, so most options for $.editable() can be passed through the options parameter of the helpers.

Requirements

Usage

Assuming a Rails 3 project, in your Gemfile, add:

gem 'jeditable-rails'

Suppose you have a User model with a #zip_code attribute.

<%# app/views/users/show.html.erb %>
<h1>View/Edit your profile</h1>
...
<b>Zip Code:</b>
<%= editable_field @user, :zip_code %>

The helpers can be used in any view you like. The field appears as normal text to the user, but when clicked, turns into a form field that will then be submitted back to the server. By default, jeditable-rails requires an update action when a PUT is done to url_for(object), which is generated by default for Rails scaffolds.

Jeditable also requires the server to respond with the new value. For a simple update action, the code will look something like this:

# app/controllers/users_controller.rb
def update
  # update your model
  @user = User.find(params[:id])
  @user.update_attributes!(params[:user])

  format.html {
    if request.xhr?
      # *** repond with the new value ***
      render :text => params[:user].values.first
    else
      redirect_to(@user, :notice => 'User was successfully updated.')
    end
  }
end

Copyright

Copyright (c) 2011 Aidan Feldman. See LICENSE.txt for further details.