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

  1. add "type" column in user table string

  2. add user model mirror waiting field type field

    after_commit {|i| update_attribute(:type, waiting ? "userwaiting" : "usernotwaiting" )} 
  3. create new models userwaiting , usernotwaiting

    class userwaiting < user end class usernotwaiting < user end 
  4. create active admin resources

    activeadmin.register userwaiting # .... end activeadmin.register usernotwaiting # .... end 
  5. 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.

  1. step 3 , 4 above

  2. then create scopes

    #model/user.rb scope :waiting, where(:waiting => true) scope :not_waiting, where(:waiting => false) 
  3. 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

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -