ruby on rails - Two pages for the same resource - ActiveAdmin -
currently have user
model, registered in user.rb
new resource activeadmin. generated page displays users scopes (all
/journalists
/startup_employees
). want create page same resource, , same scopes, there should records waiting
field set true
(and previous page should displays :waiting => false
). how that? know filters, need 2 separate pages, 2 links in menu.
// solution
it easier advices (thanks guys!):
activeadmin.register user, :as => 'waitlist user' menu :label => "waitlist" controller def scoped_collection user.where(:waitlist => true) end end # code scope :all scope :journalists scope :startup_employees end
activeadmin.register user controller def scoped_collection user.where(:waitlist => false) end end # code scope :all scope :journalists scope :startup_employees end
sti (single table inheritance) can used create multiple "sub-resources" of same table/parent model in active admin
add "type" column in user table string
add
user
model mirror waiting field type fieldafter_commit {|i| update_attribute(:type, waiting ? "userwaiting" : "usernotwaiting" )}
create new models
userwaiting
,usernotwaiting
class userwaiting < user end class usernotwaiting < user end
create
active admin
resourcesactiveadmin.register userwaiting # .... end activeadmin.register usernotwaiting # .... end
you can run first-time sync in console
user.all.each {|user| user.save}
..............
another way skip type column (steps 1,2 , 5) , solve rest scopes.
step 3 , 4 above
then create scopes
#model/user.rb scope :waiting, where(:waiting => true) scope :not_waiting, where(:waiting => false)
scopes in
active admin
#admin/user.rb scope :waiting, :default => true #admin/user_not_waitings.rb scope :not_waiting, :default => true
just make sure other scopes in these 2 pages filtered on waiting/not_waiting
Comments
Post a Comment