FAQ - activescaffold/active_scaffold GitHub Wiki

I’m using ActiveScaffold, but it looks like a regular scaffold (ugly). Why?

First thing to check is that you’re including the stylesheet in your layout. Refer back to the steps in Getting Started to see how to include the stylesheet. And you should check the page source, too, to make sure the <style> tag is in there.

If you’ve got that, then check the views directory for your controller. If you’re using a PostsController, then check app/views/posts. Delete (or move) all views out if this directory. There’s a chance you may have run Rails’ built-in scaffold generator, and those views and partials are overriding ActiveScaffold’s own.

Still not working? Come ask in the forums, and mention that you’ve already checked this FAQ.

500 Internal Error? That’s not helpful!

Yeah, you’re right, it’s not really. This error message is designed to walk a fine line between being useful for developers and for end-users, kind of like Gmail’s error messages. The trick here is to know, as a developer, that a 500 response means that an exception happened in your code. Check out the last bit of logs/development.log right after you see a 500 response, and you’ll get to see the actual error.

My associated models look like #<User:0xb7c88a2c>. How can I change that?

You want to define a to_label method for your model.

class User < ActiveRecord::Base
  def to_label
    "User: #{username}"
  end
end

Those subforms are slick, but I want to turn them off. How can I simplify associations on the form?

The form_ui = :select option lets you switch the form interface from the standard subform setup to a simple select setup. This configuration can be set per-column.

class UsersController < ApplicationController
  active_scaffold :users do |config|
    # users will no longer be able to create/edit Roles from the Users forms
    config.columns[:roles].form_ui = :select
  end
end

How can I add autocompletion to the form?

You can use RecordSelect integration.
Also, you can use a form override to insert all the javascript necessary. Here’s an example from a user in the Google Group, using a partial:

<div style="height: 100px;">
  <label for="record_identity_type">Identity Type</label>
  <%= text_field_tag 'record[identity_type]', @record[:identity_type], :id => 'record_identity_type' %>
  <div class="auto_complete" id="identity_type_autocomplete_<%=@record[:id]%>" style="{height: 80px;}"></div>
  <%= javascript_tag("new Autocompleter.Local('record_identity_type',
    'identity_type_autocomplete_#{@record[:id]}',
    ['User', 'Group', 'AdminUser'],
    {fullSearch: true, frequency: 0, minChars: 1});") -%>
</div>

ActiveScaffold is complaining about a Malformed Constraint. What should I check?

If you are noticing this when trying to open a nested scaffold, the first thing to check is that you have your associations set up in both directions. For instance, if a UserGroup has_many Users, then make sure that a User belongs_to a UserGroup. If that doesn’t fix your problem then take another look at your associations – is there a clear “reverse” association? For example, consider the following setup:

class Project < ActiveRecord::Base
  has_many :projects_users
  has_many :administrators, :through => :projects_users, :source => :user, :conditions => "projects_users.role_type = 3"
  has_many :managers, :through => :projects_users, :source => :user, :conditions => "projects_users.role_type = 2"
  has_many :workers, :through => :projects_users, :source => :user, :conditions => "projects_users.role_type = 1"
end

class User < ActiveRecord::Base
  belongs_to :organization
  has_many :projects_users
  has_many :projects, :through => :projects_users, :source => :project
end

This setup may not work as well when ActiveScaffold is trying to nest Projects for a given User. In order to nest successfully, ActiveScaffold needs to know what the reverse association is. In this case the Project doesn’t have a clear single link to the User model – it has three specialized associations. To remedy the situation, you should add:

class Project < ActiveRecord::Base
  has_many :users, :through => :projects_users, :source => :user
  ...
end

I’ve got a table with lots of associations, and my database is choking. Why? What can I do?

ActiveScaffold attempts to utilize eager loading when displaying the list, under the assumption that every association column will need to display something about the associated records. If this is too much, you have two options:

  1. Remove some association columns from the list (e.g. config.list.columns.exclude :association_column)
  2. Disable the eager loading for some association columns by setting config.columns[:association_column].includes = nil

I’m adding stuff to params[:record] but ActiveScaffold doesn’t use it. Why?

ActiveScaffold doesn’t just apply the whole params[:record] hash. Instead, it whitelists fields it expects from the form. Which is to say, if ActiveScaffold didn’t know that role_id was supposed to be on the form, it will ignore the params[:record][:role_id] entry. If it didn’t work this way, then URL hackers could submit extra data and do all kinds of fun things including privilege escalation.

If you need to apply your own data to the record before its gets saved, what you should do instead is define before_create_save(record) or before_update_save(record) on your controller. ActiveScaffold will check for these methods and pass them the record object so you can do common things like attach the current user as the record’s owner.

I need to customize the CSS (or JavaScript). What’s the best way?

Don’t edit the ActiveScaffold files in public/! These files are automatically copied from vendor/plugins/active_scaffold every time the server starts, to make sure you’re using the latest code. Instead, treat them the same way you’d treat the rest of the ActiveScaffold code – override them somewhere else, or use Piston and edit the original file in vendor/plugins/active_scaffold.

For example, if you want to customize the CSS, create public/stylesheets/active_scaffold_overrides.css and include that file in your layout by placing <%= stylesheet_link_tag 'active_scaffold_overrides' %> after the <%= active_scaffold_includes %>.

How do I set configuration options globally so that they affect all controllers?

Configuration options that you wish to set globally for all controllers (as long as that option is marked as global in the ActiveScaffold API documentation) must be placed in your application.rb file. The format for setting global configuration options is:

class ApplicationController < ActionController::Base

  ActiveScaffold.set_defaults do |config|
    config.   #fill in configuration option here
  end 
end

Rows from some subforms never are saved. Why?

When blank rows are shown automatically in subforms (without clicking in add new), ActiveScaffold check if some field in row has a non-default value, and date and boolean fields are ignored in this check. So neither rows with all fields with default value are saved, neither rows which all fields are dates or booleans are saved.

When you turn off blank rows, this check is skipped, so all rows added are saved, even blank rows.

active_scaffold parent model was looking for child’s/associated model’s overridden field or vice-versa. Why?

comment out “helper :all” in your application_controller.rb [application.rb].

‘has_many :through’ form elements aren’t appearing. Why?

Active_scaffold only shows form elements for write-able attributes. By default in Rails, records of ‘has_many :through’ associations are read-only. To get around this, simply add ‘:readonly => false’ to the association (not the join model association), as shown:

class Book < ActiveRecord::Base
  has_many :authorships
  has_many :authors, :through => :authorships, :readonly => false
end

class Authorships < ActiveRecord::Base
  belongs_to :book
  belongs_to :author
end

class Author < ActiveRecord::Base
  has_many :authorships
  has_many :books, :through => :authorships, :readonly => false
end

The ‘has_many :through’ association should now behave just like an HABTM association.

⚠️ **GitHub.com Fallback** ⚠️