0
votes

I am trying to use scope in active admin for one of my model and I get this error undefined method reorder' for array.

I have successfully used scope in another model with active admin, I am not able to debug why this issue is coming.

Here is the code from active admin :-

ActiveAdmin.register Startup do

    scope :reached do |startups|
        startups.all
    end

end

Any ideas what could be the issue ?

2
can you possibly post some of the code that gives you the 'error undefined method' ? or this could possibly help activeadmin.info/docs/2-resource-customization.html - ajt
afaik, there is no scope method for active_admin. sure, you know what you are doing? - phoet

2 Answers

0
votes

You are returning an array instead of an ActiveRecord relation and my guess is that you are trying to chain that to a method like .order which won't work. What are you trying to scope for?

If you just want all the records you don't need a scope. If you want to narrow down your startups then you should be using something like Startup.where(#condition you want met)

0
votes

This was my association at the model level.

in startup.rb

has_many :fund_requests, :dependent => :destroy

in fund_request.rb

belongs_to :startup

I was trying to scope the fund requests where the status (an attribute in fund request) is reached.

However something like this which works at model level was not working with active admin

scope :reached do |startups|



     startups.fund_requests.where(status = ?', 'Pending')

end

this was giving me the `reorder' error

writing it like this worked for me :-

scope :reached do |startups|
        startups.joins(:fund_requests).where(['fund_requests.status = ?', 'Pending'])
    end`

I don't know why chaining was not working and joins was working.