是否可以使用范围作为与simple_form关联的源?
是否可以使用范围作为关联来源?
class User < AR scope :active_users, where('status = 4') ... # form ...
对不起,我认为这不会起作用。 范围返回ActiveRecord :: Relation,而simple_form正在查找表示现有ActiveRecord :: Association的符号(例如has_many,belongs_to)。
https://github.com/plataformatec/simple_form#associations
您可以使用集合作为源
在控制器中
@active_users = User.active_users
在视野中
<%= f.association :active_user, collection: @active_users %>