Post Meta

Bookmarks

  • Delicious
  • Digg
  • Reddit
  • Magnolia
  • Newsvine
  • Furl
  • Facebook
  • Technorati

ActiveScaffold is easy to use, to modify, and to extend to your needs.

It is easily downloadable as a plugin. And you can find many nice examples and working docs on their site.

There you are with my little howtos:

acts_as_tree

  1. in your model add a short code to let ActiveScaffold show record names instead of their object ids:
    1
    2
    3
    4
    5
    6
    
    class Department < ActiveRecord::Base
    acts_as_tree   # Show the parent/children names instead of ID in ActiveScaffold
    def to_label
    "#{long_name}"
    end
    end
  2. In your controller set up the behavior:
    1
    2
    3
    4
    5
    6
    7
    8
    
    active_scaffold :departments do |config|
    config.list.columns = [:short_name, :long_name, :parent]
    config.update.columns = [:short_name, :long_name, :description, :parent]
    config.create.columns = [:short_name, :long_name, :description,  :parent]
    config.show.columns = [:short_name, :long_name, :description,  :parent]
    list.sorting = {:parent_id  =>  'ASC'}
    config.columns[:parent].ui_type = :select
    end

When you use parent instead of parent_id, AS will know how to handle the association.

And “ config.columns[:parent].ui_type = :select” will create a select box to do the parent/children associations.

Per Request Actions / Configuration

Perhaps your application will be used by many users, so you’ll have to give them permissions to access the data. When AS is used to scaffold your models, you have the following ways to assign permissions to different user views:

  1. in your controller in active_scaffold |config| you can add an if-else / case-when structure for config.actions.exclude. But this is nasty and not DRY if you have more models.
  2. you can add a before_filter in the controller as shown in the official documentation. But this also stinks, because the “create”, “update”, … buttons / links will be shown even if they are excluded, and the user will get an 500 error when tries to use them.
  3. or, watch the official secure models demo, which sounds good. there is the documentation too.

[[continuously updated, stay tuned]]



Related posts

Leave A Comment

+ -