设置表单来获取临时变量的最佳方法是什么?

发布于 2024-09-24 11:45:45 字数 362 浏览 7 评论 0原文

我正在制作照片上传表格。在开始之前,他们有两个选择。他们可以创建一个新画廊,也可以从现有画廊中进行选择。

我认为最好的布局方式是两个有两种形式。一个用于创建,它将带他们进入创建页面。这很容易,而且实际上已经完成了。

但是第二种形式,我需要在选择框中获取图库名称并将其应用到 add_photos_to_gallery 表单 - 这对我来说很棘手。我是吗?

一个。为此表单创建一个临时变量并将其传递给控制器​​,然后根据他们选择的内容生成表单?如果是这样,我该怎么办?

b.使用 jquery 并以某种方式操纵 DOM 来创建表单?我有一些想法..

c.意识到我太笨了,不知道一些更好、更明显的事情吗?

I am making a photo upload form. Before they begin, they have two choices. They can create a new gallery, OR they can choose from an existing gallery.

I was thinking the best way to lay this out would be two have two forms. One for the create one that would take them to the create page. That's easy, and practically done.

But the second form, I need to grab the gallery name in a select box and apply it to an add_photos_to_gallery form - which is tricky for me. Do I?

a. Make a temp variable for this form and pass it to the controller, and then generate the form from what they choose? If so, how could I do that?

b. Use jquery and somehow manipulate the DOM to create a form? I got some ideas..

c. Realize I'm too dumb to know something way better and more obvious?

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

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

发布评论

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

评论(1

懷念過去 2024-10-01 11:45:45

粗略地说,我处理此问题的方法是使用一种形式,

填充选择标签,我假设您在用户模型中创建一个命名范围或关联,例如

has_many :galleries

,并用它填充选择标签

 <%= select_tag "add_photos_to_gallery", @user.galleries, :include_blank => true %>

,如果 params[ :add_photos_to_gallery] 为空,创建一个新相册,否则将其添加到所选图库。

或者,您可以包含一个复选框,根据他们是否想要使用现有图库来打开或关闭选择标签。

roughly speaking the way I would approach this is with one form,

to populate the select tag, i am assuming you create a named scope or association in your user model, eg

has_many :galleries

and populate the select tag with it

 <%= select_tag "add_photos_to_gallery", @user.galleries, :include_blank => true %>

and if the params[:add_photos_to_gallery] is blank, create a new album otherwise add it to the selected gallery.

Or you could include a checkbox to toggle on or off the select tag based on if they want to use an existing gallery or not.

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