in-place edit in Rails 3
Asked Answered
S

2

10

There are a few options for editing a model in-place while in the Show page, i.e. without having to load a form in the Edit page. For example, see http://www.ruby-toolbox.com/categories/rails_in_place_editing.html.

Has anyone had any experience using any of these options (or others) in Rails 3? Any pointers or advice?

In my case, I have a fairly long form composed of a variable number of items. From a usability point of view, it makes good sense to edit the text in these items in the same page, instead of needing an Edit button for each one that sends the user to an edit page for the particular item.

Shilohshim answered 16/8, 2010 at 6:45 Comment(0)
T
13

Excellent question!

  • in_place_editing is by dhh, Rails creator. It's maintained by the Rails core team. So it certainly should be looked into.

  • Hobo is a large framework that features in-place editing front and center. It's a smooth package but may be more than what you want or need.

Updated for Rails 3 Ryan of Railscasts recommends the Best in Place gem. See the Railscast with sample code and more info.

Telefilm answered 16/8, 2011 at 12:31 Comment(1)
Note that in_place_editing is Scriptaculous-based. Rails 3.1 and up uses jQuery now, so this isn't an out-of-the-box solution anymore.Fuddyduddy
L
1

Sure it makes sense to me. I do it all the time.

For example, I am working on a complex polymorophic nested model form and it only has two views. An index, and a partial for dynamically adding more attributes to it.

If you know AJAX, that can really help your UI in that your users will not even have to click a save button.

To accomplish a bare minumum of this. Set up an index.html.erb with your form inside it.

In your controller, you could specify your actions like so :

def update
  @quick_fact = @organization.quick_facts.find(params[:id])
  if @quick_fact.update_attributes(params[:tab])
    flash[:notice] = 'Text Tab was successfully updated.'
    redirect_to quick_facts_organization_path(@organization)
  else
    render :action => "index", :id => params[:id]
 end
end
Limpkin answered 17/8, 2010 at 14:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.