开发者

How to filter records in Nested Active Scaffold records?

I am using active scaffold to list my users. The users has many published posts and unpublished posts. I need two links in my users active scaffold table "Published posts" and "unpublished po开发者_Python百科sts". When clicked on Published posts, it should display all the published posts fields under the user record and the same for un published posts.

I used nested to list all the posts for the user in the active scaffold but I am not able to filter the posts records based on the column "publised?" .. how can i do it ?

please help


Try something like:

class User < ActiveRecord::Base

...

has_many :published_reports, :class_name => "Report", :conditions => "reports.published = 1"
has_many :unpublished_reports, :class_name => "Report", :conditions => "reports.published = 0"

...

end

class UsersController < ApplicationController

active_scaffold :users do |config|
    ...

    config.actions = [:nested, :list, :show, :field_search]
    config.nested.add_link("Published", :published_reports)
    config.nested.add_link("Unpublished", :unpublished_reports)
    ...

end

end
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜