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

Create aliases for (long) search fields #536

Closed
wants to merge 14 commits into from
Closed

Create aliases for (long) search fields #536

wants to merge 14 commits into from

Conversation

glampr
Copy link

@glampr glampr commented May 3, 2015

Allow to alias (possibly long) search fields with (shorter) descriptions.
Works like ransacker, but uses already valid search fields, instead of requiring to write Arel.
Useful for converting long search fields to shorter, to save url length for GET requests.

Usage

class User
  translates :profile_text # from globalize gem
  has_many :works

  ransacker_alias :free_text, :translations_profile_text_or_works_translations_title_or_works_translations_description
end

User.search(free_text_cont: "some_text")
# same as User.search(translations_profile_text_or_works_translations_title_or_works_translations_description_cont: "some_text")

end
end

def ransack(params = {}, options = {})
params.keys.each do |k|
search_attr = k.to_s.sub(/_#{Ransack::Predicate.detect_from_string(k.to_s)}$/, Ransack::Constants::EMPTY)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line is too long. [117/80]

@glampr
Copy link
Author

glampr commented May 3, 2015

Also mentioned in #253

object.send "#{object.klass._ransacker_aliases[search_attr]}_#{search_pred}" if object
else
object.send @method_name if object # use send instead of public_send
end

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

end at 16, 6 is not aligned with if at 12, 5

@jonatack
Copy link
Contributor

Thanks for the contribution. Closed by #623.

@jonatack jonatack closed this Dec 19, 2015
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

Successfully merging this pull request may close these issues.

3 participants