V
V
Vitaly Igorevich2015-06-30 13:24:39
Ruby on Rails
Vitaly Igorevich, 2015-06-30 13:24:39

Why don't ransortable_attributes and ransackable_associations work in the ransack gem?

I am using ransortable_attributes to set the attributes available for sorting. But she doesn't work. That is, the attributes specified in ransackable_attributes are still available for sorting. How to do it right?
Second question.
I am setting associations through the ransortable_attributes function. But in the form in the attribute_select function, the associations are not displayed. They are only displayed if they are specified explicitly. For example like this:

s.attribute_select associations: [:information, :setting]

Third question.
If you specify the associations explicitly, as in the previous example, then I cannot set the css class for attribute_select.
This is how it doesn't work:
s.attribute_select associations: [:information, :setting], class: 'form-control'

But this is how it works: Tell me how to fix these problems? Model code:
s.attribute_select Hash.new, class: 'form-control'
class User < ActiveRecord::Base
  # some code

  def self.ransackable_attributes(auth_object = nil)
    %w(
      email
      current_sign_in_ip
      last_sign_in_ip
      created_at
      updated_at
    )
  end

  def self.ransortable_attributes(auth_object = nil)
    %w(
      email
      created_at
      updated_at
    )
  end

  def self.ransackable_associations(auth_object = nil)
    %w(
      information
      setting
    )
  end
end

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question