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.

4

2 回答 2

13

好问题!

  • in_place_editing由Rails 的创建者dhh 编写。它由 Rails 核心团队维护。所以当然应该调查一下。

  • Hobo是一个大型框架,具有前端和中心的就地编辑功能。这是一个流畅的包,但可能比您想要或需要的更多。

Railscasts的 Rails 3 更新 Ryan 推荐Best in Place gem。请参阅带有示例代码和更多信息的Railscast 。

于 2011-08-16T12:31:37.800 回答
1

当然这对我来说很有意义。我一直都这样做。

例如,我正在研究一个复杂的多态嵌套模型表单,它只有两个视图。一个索引和一个用于动态添加更多属性的部分。

如果您了解 AJAX,那么这确实可以帮助您的 UI,因为您的用户甚至不必单击保存按钮。

做到这一点的最低限度。设置一个 index.html.erb,其中包含您的表单。

在您的控制器中,您可以像这样指定您的操作:

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
于 2010-08-17T14:50:13.580 回答