I have this code:
class ArticlesController < ApplicationController
active_scaffold :articles do |config|
config.label = "Manage my articles"
config.actions.exclude :show
form_cols = [:name, :summary, :content, :author, :category, :article_date]
config.columns = form_cols
config.list.sorting = {:content_file_name => :asc}
config.columns[:category].css_class = 'categories'
config.columns[:category].clear_link
config.columns[:category].form_ui = :select
......
and models
class Article < ActiveRecord::Base
belongs_to :category, :class_name => 'Category'
end
class Category < ActiveRecord::Base
has_many :articles, :foreign_key => :category_id
end
Category is mapped on this table
CREATE TABLE `categories` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(255) DEFAULT NULL,
`active` tinyint(1) DEFAULT '1',
`group` varchar(255) DEFAULT 'novel',
PRIMARY KEY (`id`)
);
i want to show only categories with a particular "group" depending on the user_type.
The problem is that i don't know how to filter the rows in a relation.
I can see that activescaffold perform two queries, one for the articles and a second for the Category ( SELECT * FROM categories
) so a want to change this second query (like SELECT * FROM categories
where group='something'.
do you have any suggestion?
thanks