ActiveScaffold and RecordSelect

8 Comments

Today, I would like to show how you my integeate recordselect into activescaffold for rails3.
I will use my players/team example as usual.
My example will show you how to use :record_select instead of :select for team association in players controller.

Let s start by adding recordselect to our application

rails plugin install https://github.com/vhochstein/recordselect.git 

Adding recordselect includes to application layout

<%= active_scaffold_includes %>
<%= record_select_includes %> 

Enabling recordselect in teams_controller

teams_controller.rb 

  class TeamsController < ApplicationController 
    record_select :per_page => 3, :search_on => [:name], : order_by => 'name' 
    ...

Adding recordselect routes for teams_controller

routes.rb 

  resources :teams do 
    as_routes
    record_select_routes 
  end 

Changing form_ui to :record_select for team column

players_controller.rb 

  active_scaffold :player do |conf| 
    conf.columns[:team].form_ui = :record_select
    ...

Restart your application and you should be able to choose a team for a player using record_select.

ActiveScaffold: Refresh List after CRUD

7 Comments

Today I would like to introduce a new option for Create, Delete and Update Action named ‘refresh_list’. The purpose is to refresh the whole list after corresponding action, which might be quite useful, especially if action has also side effects on sibling records.

In addition records are inserted according to current sorting after update/create operations. However, disadvantages are higher server load and that you may not see inserted/updated records in result view.

Configuration is fairly easy. Let s change my famous players controller to activate this new feature:

class PlayersController < ApplicationController
  active_scaffold :player do |conf|
    ....
    conf.create.refresh_list = true
    conf.update.refresh_list = true 
    conf.delete.refresh_list = true 
    ....
  end
end

If you would like to enable it for all controllers, you may do the following:

class ApplicationController
  ActiveScaffold.set_defaults do |conf|
    conf.create.refresh_list = true
  end 
end

ActiveScaffold: Batch Destroy

Leave a comment

Last time I ve talked about batch updates. Today I would like to focus on batch destroy.
I will assume that you have read my last post.

Enabling batch_destroy action

class PlayersController < ApplicationController
  active_scaffold :player do |conf|
    ....
    conf.actions << :batch_base 
    conf.actions << :batch_destroy 
    ....
  end
end

If you reload your page, you will see another entry in batch collection pop-up menu, which you might use to destroy marked or listed records.

Process Mode Configuration

There s one thing I have nt mentioned so far. In default mode batch_destroy will perform a “normal” activerecord destroy, which includes validation, record base_authorization and callbacks,…. That might take quite some time if you want to destroy a huge number of records.

You can configure to speed up, but you have to pay a price:

class PlayersController < ApplicationController
  active_scaffold :player do |conf|
    ....
    conf.batch_destroy.process_mode = :delete_all 
    ....
  end
end

process_mode delete_all means that we will use ActiveRecords delete_all method to destroy all records.
But be careful and let me tell you about the price you have to pay:

  • No record base authorization
  • No record level errors
  • No ActiveRecord callbacks, validations,…

Just to complete this story, you ve got same configuration option in batch_update.

Wish you a great weekend!