Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

let enum select options use instance method #44

Closed
leomao10 opened this issue Sep 9, 2012 · 0 comments
Closed

let enum select options use instance method #44

leomao10 opened this issue Sep 9, 2012 · 0 comments

Comments

@leomao10
Copy link
Contributor

leomao10 commented Sep 9, 2012

I just create a report class like this:

  class ContactReport 
    include Datagrid

    datagrid_attribute :current_user
    datagrid_attribute :sites

    def initialize(current_user, attributes = {})
      super(attributes)
      self.current_user = current_user
      if current_user
        self.sites      = current_user.sites.active.doing_jsa
        scope do
          PsmContact.index_scope.restricted(sites).includes(:user)
        end
      end
    end
  end

and now I want to add a enum filter, and its select item should be current_user.sites

    filter(:site_id, :enum, :select => lambda { current_user.sites.flatten }, :prompt => "All sites") do |value|
      where(:site_id => value)
    end

However, I could not do that because the context for the lambda is ContactReport and it do not have a current_user methods.

Could be helpful if you can enable the select option to use current instance's method

bogdan added a commit that referenced this issue Sep 9, 2012
pass object params to enum_filter#select, fix issue #44
@bogdan bogdan closed this as completed Sep 12, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants