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

Provide additional arguments to scope #769

Closed
shir opened this issue Feb 17, 2017 · 1 comment
Closed

Provide additional arguments to scope #769

shir opened this issue Feb 17, 2017 · 1 comment

Comments

@shir
Copy link

shir commented Feb 17, 2017

Hi. Is there a way to pass additional arguments to search scope. Here is example that I'm looking for:

class Client
  class << self
    def ransackable_scopes(_auth_object = nil)
      %i(filter_by_status)
    end

    def filter_by_status(status, context)
      case status
      when 'all'
        where(nil)
      when 'closed'
        where(%("status" == 'closed' OR id IN (:open_ids)), status: context[:user].try(:open_ids) || [])
      end
    end
  end
end

class ClientsController
  def index
    @q = Client.search(params[:q], context: { user: current_user }) # `context` or `additional_params` or `whatever`
    @clients = @q.result
  end
end

So I may pass additional argument from controller which I may use in scope.

@scarroll32
Copy link
Member

This issue appears more to be a HOW-TO issue rather than a bug in Ransack. We are in the process of cleaning up the Ransack gem and repo. If this issue is still relevant could you please ask it on StackOverflow?

If you think it is an issue with Ransack, please provide a repo with the issue and / or a pull request with failing tests. If you don't know how to do this, indicate it in the issue and we will look into it eventually.

Thank you

https://github.com/activerecord-hackery/ransack/blob/master/CONTRIBUTING.md

#794

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