formattastic - :string 字段值作为数组且未找到-s
是否有可能从 :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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我已经使用 task_ids 的创建属性访问器解决了这个问题
I've solved this issue with creation attribute accessor for task_ids
处理这个问题的一种方法是使用 :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.