justinfrench/formtastic — Issue #740: Mongoid belongs_to select raises NoMethodError and always returns empty results
Author: rgarner
Created: 2011-11-11 12:30:49+00:00
State: open

This [pull request](https://github.com/justinfrench/formtastic/pull/545) was ostensibly to fix the `NoMethodError` problem with Mongoid relations.

However, it's still raising `NoMethodError` with select fields in 2.0.2 (a `Mongoid` `belongs_to` in my case). `if reflection.options` should (I think) read `if reflection.respond_to(:options)` in each case. However, this just masks a further problem - on Mongoid, if you use `.scoped(:conditions => nil)` or `.scoped(:conditions => {})`, the query will always return no results, meaning a blank select box. Looks like we need to conditionally omit the `scoped(:conditions => ...)` hash.

The workaround - for `undefined method 'options' for #` is to supply the collection to the input explicitly, e.g. `= input :category, :collection => Category.all`