Activescaffold empower user to configure list

4 Comments

Mr Bonefish created a plugin called active_scaffold_config_list which empowers the user to hide and show columns in list view. That s a really valuable feature and should still exist in the world of rails 3, I thought.

You may find the result of my thoughts in a fork of active_scaffold_config_list.
You are still able to hide and show columns. In addition I ve empowered the user to change the order of list columns by simple drag and drop. Please note that you cannot drag and drop the columns itself, but instead you can drag and drop the column names in the config_list action form.

Let me guide you through the steps to install and configure config_list plugin.

We will start with installation of active_scaffold_config_list plugin.

rails plugin install git://github.com/vhochstein/active_scaffold_config_list.git

Afterwards, we have to add config_list action to our controller.

active_scaffold :player do |conf|
  conf.actions << :config_list
end

Yes and thats it. You should see a new collection action_link, which empowers your users to configure list view as they like.

Bonefish implemented another neat feature, which survived transformation to rails 3. You may define a set of default_columns for your list_view.
That s really useful if you ve got tons of list columns available, but as a default you would only like to show a subset of them.

conf.config_list.default_columns = [:name, :salary, :team]

Activescaffold how to automatically open a nested link

2 Comments

From time to time I was confronted with the following feature request by my users:
If I filter list view for a specific record, could nt you open a nested link automatically?

There a several approaches to achieve this and you have to decide if you would like to do it on server or client-side with corresponding pro’s and con’s.

I ve implemented a server side version which requires render_component plugin.
However, that one is installed automatically in my howto application.

Let me show you how it works in a quite short example:

class TeamsController < ApplicationController
  active_scaffold :team do |conf|
    conf.nested.add_link(:players)
    conf.list.nested_auto_open = {:players => 1}
  end
end

Our starting point is a nested link to players model.
Next line is doing all the magic, we configured that players nested link should be automatically opened if there is only 1 team record in list view.
You could also pick 2 or even 10 records in list views.

Human Conditions with Field Search

5 Comments

Today, I would like to introduce a new experimental feature. Currently, if you are using field_search you can see in top row of your record set that your list is currently filtered. However, you may not remember current search criteria. This is why I have added a little feature called “human conditions”, which will try to inform the user about the current search criteria.

Just try it out, it s fairly easy to activate.

class TeamsController < ApplicationController
  active_scaffold :team do |conf| 
    conf.actions.swap :search, :field_search 
    conf.field_search.human_conditions = true 
  end 
end

One Step rails app with activescaffold installation

5 Comments

At the beginning I thought, great my process described in my post how to setup activescaffold with rails 3 is quite easy and only consists of a view steps. Unfortunetly, I had to realize that even these few steps are too many if you have to do that frequently.

Therefore I ve tried to further reduce steps it takes to install my little howto application. I ve managed to get it down to one step (if you do not count downloading a ruby script :-))

That s a real time safer for me and will be for you if you are following my posts and try these things out. In addition it can be used to install any new activescaffold enabled rails 3 app.

You may find that install script at the following location: One Step Activescaffold

If you want to try it out just download the following file: https://github.com/vhochstein/one_step_active_scaffold/raw/master/one_step_activescaffold.rb and run it on your computer without any options.

At the end you are a proud creator of my little how-to application. you just have to call ‘rails s’ to start the application.

If you like it you can use it even for your own apps. This little script takes several arguments, these empower you to set application name, js_library, your preferred database system and db user and password.
If you would like to create your own models instead of my player and team ones… Sure no problem. You just have to create a special file in the same directory which includes the required commands to create these models.

Let’s take a look at some examples:

ruby one_step_activescaffold_app.rb

That s the default, which creates my little how-to.

ruby one_step_activescaffold_app.rb my_new_app jquery mysql

Creates my little how-to with the name ‘my_new_app’ using mysql and jquery.

ruby one_step_activescaffold_app.rb my_new_app jquery postgres john top_secret

Same as before, but using postgres and db_user is ‘john’ and password is ‘top_secret’

model_setup.rb:
puts %x[rails g active_scaffold coach name:string]

ruby one_step_activescaffold_app.rb

Creates my little how-to, but instead of creating team and player model, we create a coach model.

ActiveScaffold and Trees with Ancestry Plugin

7 Comments

Today I would like to show how easy it can be to setup a tree structure with activescaffold.

At the end of this post we should have a tree structure in which we can CRUD elements, even changing the parent of a child.
In addition we can sort children of a parent by drag and drop.

As usual we will need my little how-to application.

1. Create a new menu model

rails g active_scaffold Menu name:string action:string position:integer ancestry:string
rake db:migrate

position attribute is needed for sorting and ancestry attribute for ancestry plugin.

2. Install plugins

rails plugin install git://github.com/rails/acts_as_list.git 
rails plugin install git://github.com/vhochstein/active_scaffold_sortable.git 
rails plugin install git://github.com/stefankroes/ancestry.git 

3. Include ancestry into Menu Model

app/model/menu.rb

class Menu < ActiveRecord::Base
  has_ancestry
end

4. Configure Menu Controller

app/controller/menus_controller.rb

class MenusController < ApplicationController
  active_scaffold :menu do |conf|
    conf.nested.add_scoped_link(:children)  #nested link to children
  end

  protected 

  # If nested let active_scaffold manage everything
  # if not just show all root nodes
  def beginning_of_chain 
    nested? ? super : active_scaffold_config.model.roots 
  end 

  # Assign parent node to just created node
  def after_create_save(record) 
    if (nested? && nested.scope) 
      parent = nested_parent_record(:read) 
      record.send("#{nested.scope}").send(:<<, parent) unless parent.nil? 
    end
  end 
end

5. Starting server and creating menu records

Create records, edit records, delete records,…..

6. Something is missing…. Sorting

app/model/menu.rb

class Menu < ActiveRecord::Base
  acts_as_list
  has_ancestry
end

You have to restart your server to enable sorting feature in your UI.