I'm getting errors when I try to display a select dropdown of enums from my model.
I have defined an enum in my model Plants
:
class Plant < ActiveRecord::Base
belongs_to :garden
enum life_cycle: [ :annual, :perennial, :biennial ]
enum sun: [ :full_sun, :part_shade, :full_shade ]
enum sow_method: [ :direct, :indoor, :direct_indoor ]
end
I want the corresponding input to display those enum options. I see from Saving enum from select in Rails 4.1 it can be approached like this (in _form.html.haml
):
= simple_form_for(@plant) do |f|
= f.error_notification
.form-inputs
= f.input :name
= f.input :scientific_name
= f.input :height
= f.input :width
= f.input :spacing
= f.input :life_cycle, :as => :select, :collection => Plant.life_cycle.keys.to_a
= f.input :sun
= f.input :sow_method
= f.input :direct_seed_start
= f.input :direct_seed_stop
= f.input :indoor_seed_start
= f.input :indoor_seed_stop
= f.input :transplant_start
= f.input :transplant_stop
= f.association :garden
.form-actions
= f.button :submit
When I try to visit the edit page I get an "undefined method" error. I'm very new to ruby so I'm probably misunderstanding something simple...
Thanks