{"action":"closed","issue":{"url":"https://api.github.com/repos/hashrocket/decent_exposure/issues/114","labels_url":"https://api.github.com/repos/hashrocket/decent_exposure/issues/114/labels{/name}","comments_url":"https://api.github.com/repos/hashrocket/decent_exposure/issues/114/comments","events_url":"https://api.github.com/repos/hashrocket/decent_exposure/issues/114/events","html_url":"https://github.com/hashrocket/decent_exposure/issues/114","id":48159452,"number":114,"title":":ancestor option causes wrong scope on singular expose","user":{"login":"smostovoy","id":383681,"avatar_url":"https://avatars.githubusercontent.com/u/383681?v=3","gravatar_id":"","url":"https://api.github.com/users/smostovoy","html_url":"https://github.com/smostovoy","followers_url":"https://api.github.com/users/smostovoy/followers","following_url":"https://api.github.com/users/smostovoy/following{/other_user}","gists_url":"https://api.github.com/users/smostovoy/gists{/gist_id}","starred_url":"https://api.github.com/users/smostovoy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/smostovoy/subscriptions","organizations_url":"https://api.github.com/users/smostovoy/orgs","repos_url":"https://api.github.com/users/smostovoy/repos","events_url":"https://api.github.com/users/smostovoy/events{/privacy}","received_events_url":"https://api.github.com/users/smostovoy/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2014-11-08T07:58:59Z","updated_at":"2015-09-10T14:46:16Z","closed_at":"2015-09-10T14:46:16Z","body":"Hey,\r\nI'm trying to scope records. It's a one-to-many ralation like Company<-Employee.\r\n```ruby\r\nexpose(:company) { current_company }\r\nexpose(:employees, ancestor: :company) \r\nexpose(:employee, ancestor: :company)  \r\n```\r\nIn this example the last one item - singular - doesn't work as it tries to find/build record on ancestor instant object:\r\n```\r\n  NoMethodError - undefined method `new' for #<Company:0x007fae8a405278>\r\n```\r\nSeems like the problem is in https://github.com/hashrocket/decent_exposure/blob/master/lib/decent_exposure/active_record_strategy.rb#L25\r\n```ruby\r\n def ancestor_scope\r\n      if plural?\r\n        controller.send(options[:ancestor]).send(inflector.plural)\r\n      else\r\n        controller.send(options[:ancestor])\r\n      end\r\n    end\r\n```\r\nIf it's not plural then we get only ancestor scope and find/build record is failed in\r\nhttps://github.com/hashrocket/decent_exposure/blob/master/lib/decent_exposure/active_record_strategy.rb#L58 \r\n```ruby\r\n    def singular_resource\r\n      if id\r\n        scope.send(finder, id)\r\n      else\r\n        scope.new\r\n      end\r\n    end\r\n```\r\nI can make a pull request if you agree that it should be fixed."}}