Permalink
Browse files

added more detail around the update action response

  • Loading branch information...
1 parent 03e6091 commit bd07ab435ed49e0d7baf0fadb1dd157438ff8e21 @afeld committed Jan 2, 2012
Showing with 26 additions and 13 deletions.
  1. +26 −13 README.md
View
@@ -15,22 +15,35 @@ Assuming a Rails 3 project, in your Gemfile, add:
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 %>
-
- #app/controllers/users_controller.rb
- format.html {
+```erb
+<%# 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:
+
+```ruby
+# 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?
- render :text => params[:user].values.first
+ # *** repond with the new value ***
+ render :text => params[:user].values.first
else
- redirect_to(@user, :notice => 'User was successfully updated.')
+ redirect_to(@user, :notice => 'User was successfully updated.')
end
- }
-
-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.
+ }
+end
+```
## Copyright

0 comments on commit bd07ab4

Please sign in to comment.