访问semantic_fieds_for循环/formtastic中的对象

发布于 2024-09-28 13:57:57 字数 403 浏览 0 评论 0原文

模型具有 Accepts_nested_attributes_for 关系,形式如下:

= semantic_form_for @obj, :url => path do |f|  
  =  f.inputs do
    = f.input :name
    = f.semantic_fields_for :photos do |p|
      = p.inputs :desc
  = f.buttons

该形式运行良好,一切都很好。但是,我想在现场附近显示每张照片,以便用户可以知道她要注释哪张照片。无论如何,要在 fields_for 循环内访问 photo.id 吗?

编辑:

有什么方法可以改变本示例中照片字段的渲染顺序。据我所知,到目前为止,这个顺序是相当随机的。

Model has accepts_nested_attributes_for for the relation and the form is as follows:

= semantic_form_for @obj, :url => path do |f|  
  =  f.inputs do
    = f.input :name
    = f.semantic_fields_for :photos do |p|
      = p.inputs :desc
  = f.buttons

The form works well and everything is fine. However, I would like to display each photo near the field, so the user could se which picture she is going to annotate. Is there anyway, to access photo.id inside the fields_for loop?

Edit:

Is there any way to alter the order in which photos fields will be rendered in this example. As far as I can tell till now, that order is pretty random.

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

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

发布评论

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

评论(1

一杆小烟枪 2024-10-05 13:57:57

嗯,这很简单,可以通过以下方式访问该对象:

p.object

:-)

问题的第二部分通过以下方式解决:

default_scope order(...)

Well this was easy enough, the object is accesible by:

p.object

:-)

Second part of the question is solved with:

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