I have three models :
class LevelTwoArea < ActiveRecord::Base
has_many :places, dependent: :restrict
end
class Place < ActiveRecord::Base
belongs_to :level_two_area
has_many :producers, dependent: :restrict
validates_presence_of :level_two_area_id
end
class Producer < ActiveRecord::Base
belongs_to :place
validates_presence_of :place_id
end
I also have a controller with an ActiveScaffold per model.
Problem is, when i want to create a new Place
, the scaffold spits an error to the log :
ActiveScaffold::ReverseAssociationRequired (Association producers: In order
to support :has_one and :has_many where the parent record is new and the child
record(s) validate the presence of the parent, ActiveScaffold requires the
reverse association (the belongs_to).)
I don't understand why...
Notice that :
- Other similar scaffolds do work
i can create records and use associations in the console :
>> Place.new name: 'PONVOGO', level_two_area_id: 10144 => #<Place id: nil, name: "PONVOGO", latitude: nil, longitude: nil, producers_count: nil, level_two_area_id: 10144, created_at: nil, updated_at: nil, marker: nil> >> _.save => true >> Producer.first.place.producers => [#<Producer id: 1, name: "KOFFI YAO GREGOIRE", place_id: 43, created_at: nil, updated_at: nil>]
The problem disappears when i remove the
has_many :producers
, though the association macros look perfectly normal- The problem won't disappear if i remove the
dependent: :restrict
option - i have a
producers_census
column on myPlace
model, i suspect this to mess things up but would like to have confirmation before doing heavy refactoring. Removing this column from the scaffold won't fix the problem.
fields on the places
table :
Column | Type |
--------------------------------------------------
id | integer | non NULL (PK)
name | character varying(50) | non NULL
latitude | double precision |
longitude | double precision |
producers_census | integer |
level_two_area_id | integer | non NULL (FK)
created_at | timestamp without time zone |
updated_at | timestamp without time zone |
marker | geometry |
my entire PlacesController
:
class PlacesController < ApplicationController
active_scaffold :place do |conf|
conf.columns = :name,
:level_two_area,
:latitude,
:longitude,
:producers_census
export.columns.add :id,
:level_two_area_id
[:latitude, :longitude].each {|column| conf.columns[column].options[:format] = "%.14f" }
[
create,
update,
delete,
batch_update
].each do |action|
action.link.security_method = :can_see_link?
end
batch_destroy.link.each {|sublink| sublink.security_method = :can_see_link? }
end
end
i'm on rails (3.0.5) / active_scaffold_vho (3.0.17) / ruby (1.9.2p180)