find_by
only returns a single record (or nil
if the criteria aren't matched) use where
to return a collection.
@basic = Field.where(event_id: @event.id, field_type: 'basic')
However assuming you have the association has_many :fields
defined in Event
you could also use:
@basic = @event.fields.where(field_type: 'basic')
And if you have the scope :basic, -> { where(field_type: 'basic') }
defined in Field
you can further simplify to:
@basic = @event.fields.basic
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…