ruby - How to list active records using Active scaffold with association in rails 2.3.8? -


i want list records db, active(true) in index page.

i'm using active scaffold plugin rails 2.3.8. suggestion how add active condition in controller?

here admin controller

   class admin::accountscontroller < applicationcontroller       active_scaffold :accounts |config|        config.list.sorting = {:id => :asc}        config.list.columns = [:description,:year]        config.actions = [:create, :update,:list,:search,:delete]       end    end 

models

   class account < activerecord::base      has_many :customer_accounts    end     class customeraccount < activerecord::base     belongs_to :account    end 

table structure

  create_table :customer_accounts |t|      t.integer :account_id      t.active :boolean, :default=>true      t.timestamps   end 

you can add following method controller apply conditions on active scaffold collection:

  def conditions_for_collection     unless has_role?(:admin) # if want limit records non admin users       ['customer_accounts.active ?', true]     end   end 

pasted below part explaining method on activescaffold api:

conditions_for_collection controller method

if want add custom conditions find(:all) used list, define method. may return conditions in string or array syntax. , instance method on controller, has access params , session , standard stuff.

example:

def conditions_for_collection   ['user_type in (?)', ['admin', 'sysop']] end 

you may specify joins ensure associated model available used in conditions:

  def joins_for_collection     [:customer_accounts]   end 

hope helps.


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -