0

I am using simple_form as my form builder in a rails project, with RethinkDB as the database and the NoBrainer ORM. I have set up the models to include the relationships between them however when trying to generate the select dropdown for the association, I get the error Association :currency not found. Where am I going wrong?

class Country
    include NoBrainer::Document

    belongs_to :currency
    field :name, type: String
    field :nationality, type: String
end

class Currency
    include NoBrainer::Document

    has_many :countries
    field :name, type: String
    field :code, type: String
    field :symbol, type: String
end

= simple_form_for @country do |f|
    = f.input :name, placeholder: 'e.g. Namibia', label: 'Country'
    = f.input :nationality, placeholder: 'e.g. Namibian', label: 'Nationality'
    = f.association :currency, placeholder: 'Please select one', label: 'Currency', label_method: :code
    = f.button :submit
Nicolas Viennot
  • 3,921
  • 1
  • 21
  • 22
  • So I see that NoBrainer does not yet support Reflection and this is why the f.association method does not yet work. There is a pull request however to include reflection support. – BrazenBraden Feb 17 '16 at 16:11

1 Answers1

0

You might not be doing anything wrong.

Please note that the association helper is currently only tested with Active Record. It currently does not work well with Mongoid and depending on the ORM you're using your mileage may vary.

https://github.com/plataformatec/simple_form

AFAIK your association is declared properly - but you may want to try specifying the collection to use for the options.

= f.association :currency, placeholder: 'Please select one', 
                label: 'Currency', 
                label_method: :code, 
                collection: Currency.all

If it still does not work you might want use the lower-level collection input helpers which is just some SimpleForm sugar on top of the Rails collection_select method.

= f.input :currency_id, 
          label: 'Currency',
          collection: Currency.all,
          label_method: :code, 
          value_method: :id
max
  • 96,212
  • 14
  • 104
  • 165
  • I'm guessing you are using HAML, you might need to adjust a bit if you are using Slim since the syntax for multi-line method calls is different. – max Feb 17 '16 at 10:07
  • Quite right. Seems to be simple_form not knowing how to handle associations with RethinkDB. Adding the collection makes no difference. – BrazenBraden Feb 17 '16 at 10:40
  • 1
    After much digging I found that the NoBrainer gem does not support reflection at this time although there is a pull request to include it (which does not yet work) so it should be available shortly. And to answer your question, yes I can use a collection_select providing it with the collection needed. Hopefully the above gets sorted though because that will make life a whole lot easier. – BrazenBraden Feb 17 '16 at 16:09