是否有可能使用范围,因为源与simple_form关联? [英] Is it possible to use a scope as source for association with simple_form?

查看:142
本文介绍了是否有可能使用范围,因为源与simple_form关联?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能使用范围源的关联?

 类用户< AR
  适用范围:ACTIVE_USERS,其中(状态= 4)
  ...#形式
<%= f.association:ACTIVE_USERS%GT;
...


解决方案

对不起,我不认为这会工作。作用域返回一个ActiveRecord ::关系和simple_form正在寻找一个重新presents现有的ActiveRecord ::协会(例如的has_many,belongs_to的)。一个符号

Is it possible to use a scope as source for association?

class User < AR
  scope :active_users, where('status = 4')
  ...

# form
<%= f.association :active_users %>
...

解决方案

Sorry, I don't think that will work. A scope returns an ActiveRecord::Relation and simple_form is looking for a symbol that represents an existing ActiveRecord::Association (E.g. has_many, belongs_to).

这篇关于是否有可能使用范围,因为源与simple_form关联?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆