Rails 3 中的就地编辑

发布于 2024-09-14 03:58:40 字数 375 浏览 2 评论 0原文

有几个选项可用于在“显示”页面中就地编辑模型,即无需在“编辑”页面中加载表单。例如,请参阅 http://www.ruby-toolbox.com/categories/rails_in_place_editing.html

有没有人有过在 Rails 3 中使用这些选项(或其他选项)的经验?有什么指示或建议吗?

就我而言,我有一个相当长的表单,由可变数量的项目组成。从可用性的角度来看,在同一页面中编辑这些项目中的文本是很有意义的,而不需要为每个项目提供一个编辑按钮,将用户发送到特定项目的编辑页面。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

栩栩如生 2024-09-21 03:58:41

很好的问题!

  • in_place_editing 由 Rails 创建者 dhh 编写。它由 Rails 核心团队维护。所以它当然应该被研究。

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

针对 Rails 3 进行了更新
Railscasts 的 Ryan 推荐 最佳位置 gem。请参阅 Railscast,其中包含示例代码和更多信息。

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.

终弃我 2024-09-21 03:58:41

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

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

如果您了解 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

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文