Question

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 %>
...
Was it helpful?

Solution

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).

OTHER TIPS

https://github.com/plataformatec/simple_form#associations

You can use collection for source

in controller

@active_users = User.active_users

in view

<%= f.association :active_user, collection: @active_users %>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top