formattastic - :string 字段值作为数组且未找到-s

发布于 2024-09-02 16:02:31 字数 276 浏览 5 评论 0原文

是否有可能从 :string 字段的格式形式值发送,

- semantic_form_for :project do |form|
 - form.inputs do
  = form.input :task_ids, :as => :string

如数组?目前该字段的值作为字符串发送,我不想在控制器中解析该字符串。

另外,你能给我一个想法吗 - 如果未找到提交的 id 的任务 - 捕获这种情况的最佳方法是什么 - 在控制器中进行验证还是什么?

is there any possibility to send from formtastic form value of :string field like

- semantic_form_for :project do |form|
 - form.inputs do
  = form.input :task_ids, :as => :string

as Array? Currently value of this field is sending as String and i'd like to no parse this string in controller.

Also, could you give me idea - if task with submitted id is not found - what is best way to catch this situation - validation in controller or what?

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

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

发布评论

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

评论(2

热风软妹 2024-09-09 16:02:31

我已经使用 task_ids 的创建属性访问器解决了这个问题

I've solved this issue with creation attribute accessor for task_ids

oО清风挽发oО 2024-09-09 16:02:31

处理这个问题的一种方法是使用 :as =>; :check_boxes 或 :as => :select 与 :tasks 直接关联,这将带来用户友好的额外好处。如果您坚持使用task_ids,最好重写task_ids=方法。在那里您可以处理解析数据和验证。

One way you could handle this is by using :as => :check_boxes or :as => :select with :tasks associations directly this would have added benefit of being user friendly. If you insist on using task_ids though, it's probably best to override task_ids= method. There you could handle parsing data and validating.

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