Closed smostovoy closed 9 years ago
Hey, I'm trying to scope records. It's a one-to-many ralation like Company<-Employee.
expose(:company) { current_company } expose(:employees, ancestor: :company) expose(:employee, ancestor: :company)
In this example the last one item - singular - doesn't work as it tries to find/build record on ancestor instant object:
NoMethodError - undefined method `new' for #<Company:0x007fae8a405278>
Seems like the problem is in https://github.com/hashrocket/decent_exposure/blob/master/lib/decent_exposure/active_record_strategy.rb#L25
def ancestor_scope if plural? controller.send(options[:ancestor]).send(inflector.plural) else controller.send(options[:ancestor]) end end
If it's not plural then we get only ancestor scope and find/build record is failed in https://github.com/hashrocket/decent_exposure/blob/master/lib/decent_exposure/active_record_strategy.rb#L58
def singular_resource if id scope.send(finder, id) else scope.new end end
I can make a pull request if you agree that it should be fixed.
Try removing the ancestor: :company from singular employee.
ancestor: :company
employee
Hey, I'm trying to scope records. It's a one-to-many ralation like Company<-Employee.
In this example the last one item - singular - doesn't work as it tries to find/build record on ancestor instant object:
Seems like the problem is in https://github.com/hashrocket/decent_exposure/blob/master/lib/decent_exposure/active_record_strategy.rb#L25
If it's not plural then we get only ancestor scope and find/build record is failed in https://github.com/hashrocket/decent_exposure/blob/master/lib/decent_exposure/active_record_strategy.rb#L58
I can make a pull request if you agree that it should be fixed.