Update ransack_ui to support lambda in inclusion matchers #4

Closed
steveyken opened this Issue Mar 14, 2013 · 5 comments

Comments

Projects
None yet
3 participants
@steveyken
Collaborator

steveyken commented Mar 14, 2013

Ransack UI reads the validates :inclusion => ... on models to come up with options for the dropdown boxes. This currently doesn't support cases where :in => lambda { ... }. See http://api.rubyonrails.org/classes/ActiveModel/Validations/HelperMethods.html#method-i-validates_inclusion_of

@steveyken

This comment has been minimized.

Show comment Hide comment
@steveyken

steveyken Dec 7, 2013

Collaborator

It works for arrays but not for lambdas

Collaborator

steveyken commented Dec 7, 2013

It works for arrays but not for lambdas

@ndbroadbent

This comment has been minimized.

Show comment Hide comment
@ndbroadbent

ndbroadbent Dec 9, 2013

Owner

Oh! I was totally wrong. If the lambda just returns an array, then yeah, we can definitely support this. For some reason, I thought you were talking about where the validation itself happened inside a lambda.

Owner

ndbroadbent commented Dec 9, 2013

Oh! I was totally wrong. If the lambda just returns an array, then yeah, we can definitely support this. For some reason, I thought you were talking about where the validation itself happened inside a lambda.

@steveyken

This comment has been minimized.

Show comment Hide comment
@steveyken

steveyken Dec 14, 2013

Collaborator

Yeah that's right. I'd love to replace (in models/entities/opportunity.rb)

validates :stage, :inclusion => { :in => Setting.unroll(:opportunity_stage).map{|s| s.last.to_s } }

with

validates :stage, :inclusion => { :in => -> { Setting.unroll(:opportunity_stage).map{|s| s.last.to_s } } }

At the moment, Setting is getting initialized a little too early during start up and we had a few issues before. E.g. if db hasn't been migrated yet and therefore settings table doesn't exist.

Collaborator

steveyken commented Dec 14, 2013

Yeah that's right. I'd love to replace (in models/entities/opportunity.rb)

validates :stage, :inclusion => { :in => Setting.unroll(:opportunity_stage).map{|s| s.last.to_s } }

with

validates :stage, :inclusion => { :in => -> { Setting.unroll(:opportunity_stage).map{|s| s.last.to_s } } }

At the moment, Setting is getting initialized a little too early during start up and we had a few issues before. E.g. if db hasn't been migrated yet and therefore settings table doesn't exist.

@steveyken

This comment has been minimized.

Show comment Hide comment
@steveyken

steveyken Dec 14, 2013

Collaborator

c7a03d3 resolves this

Collaborator

steveyken commented Dec 14, 2013

c7a03d3 resolves this

@steveyken steveyken closed this Dec 14, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment