jbox-web / ajax-datatables-rails

A wrapper around DataTable's ajax methods that allow synchronization with server-side pagination in a Rails app
MIT License
585 stars 228 forks source link

ArgumentError (wrong number of arguments (given 2, expected 1)) in column with custom condition #290

Closed reiallenramos closed 6 years ago

reiallenramos commented 6 years ago

Hi I'm stuck with this problem for almost a whole day now. My datatable is working properly then I decided to use custom columns. I found this project and used it as reference but I can't get it to work properly.

For context, my User model has the attributes first_name and last_name, but I need to be able to search via full_name which is a model method that simply returns a string.

I'm getting this error when I type anything in the search box

ArgumentError (wrong number of arguments (given 2, expected 1)):

app/datatables/users_datatable.rb:51:in `block in filter_full_name_condition'
app/controllers/users_controller.rb:14:in `block (2 levels) in index'
app/controllers/users_controller.rb:12:in `index'

I found a discussion that says filter method receives 2 params now but when I checked the master branch, filter method is no longer in column.rb. Although I'm not entirely sure if the error is in the filter method, I tried using the specific commit that changed this method by specifying it when I load the gem in the Gemfile but I get the same error.

I also tried the example that uses Arel syntax but still same error. Please advise.

users_datatable.rb

  def view_columns
    @view_columns ||= {
      id_number:            { source: 'User.id_number' },
      full_name:            { source: 'User.id', cond: filter_full_name_condition }
    }
  end

  private

  def data
    records.map do |record|
      {
        id_number:            record.id_number,
        full_name:            record.full_name
      }
    end
  end

  def filter_full_name_condition
    ->(column) { column.table[column.field].eq(column.search.value.to_i + 1) }
  end

user.js

.
.
.
"columns":[
      {"data": "id_number"},
      {"data": "full_name"}
    ],
.
.
.

Gemfile.lock

GIT
  remote: git://github.com/Nerian/bootstrap-datepicker-rails.git
  revision: 981ad1d67e5725494e8a569136f0fd730baaedc5
  specs:
    bootstrap-datepicker-rails (1.8.0.1)
      railties (>= 3.0)

GIT
  remote: git://github.com/ryanb/nested_form.git
  revision: 1b0689dfb4d230ceabd278eba159fcb02f23c68a
  specs:
    nested_form (0.3.2)

GEM
  remote: https://rubygems.org/
  specs:
    actioncable (5.2.0)
      actionpack (= 5.2.0)
      nio4r (~> 2.0)
      websocket-driver (>= 0.6.1)
    actionmailer (5.2.0)
      actionpack (= 5.2.0)
      actionview (= 5.2.0)
      activejob (= 5.2.0)
      mail (~> 2.5, >= 2.5.4)
      rails-dom-testing (~> 2.0)
    actionpack (5.2.0)
      actionview (= 5.2.0)
      activesupport (= 5.2.0)
      rack (~> 2.0)
      rack-test (>= 0.6.3)
      rails-dom-testing (~> 2.0)
      rails-html-sanitizer (~> 1.0, >= 1.0.2)
    actionview (5.2.0)
      activesupport (= 5.2.0)
      builder (~> 3.1)
      erubi (~> 1.4)
      rails-dom-testing (~> 2.0)
      rails-html-sanitizer (~> 1.0, >= 1.0.3)
    activejob (5.2.0)
      activesupport (= 5.2.0)
      globalid (>= 0.3.6)
    activemodel (5.2.0)
      activesupport (= 5.2.0)
    activerecord (5.2.0)
      activemodel (= 5.2.0)
      activesupport (= 5.2.0)
      arel (>= 9.0)
    activestorage (5.2.0)
      actionpack (= 5.2.0)
      activerecord (= 5.2.0)
      marcel (~> 0.3.1)
    activesupport (5.2.0)
      concurrent-ruby (~> 1.0, >= 1.0.2)
      i18n (>= 0.7, < 2)
      minitest (~> 5.1)
      tzinfo (~> 1.1)
    addressable (2.5.2)
      public_suffix (>= 2.0.2, < 4.0)
    airbrussh (1.3.0)
      sshkit (>= 1.6.1, != 1.7.0)
    ajax-datatables-rails (0.4.1)
      railties (>= 4.0)
    arel (9.0.0)
    ast (2.4.0)
    autoprefixer-rails (8.5.0)
      execjs
    axlsx (2.0.1)
      htmlentities (~> 4.3.1)
      nokogiri (>= 1.4.1)
      rubyzip (~> 1.0.0)
    axlsx_rails (0.5.2)
      actionpack (>= 3.1)
      axlsx (>= 2.0.1)
    bcrypt (3.1.11)
    bootstrap-kaminari-views (0.0.5)
      kaminari (>= 0.13)
      rails (>= 3.1)
    bootstrap-multiselect-rails (0.9.9)
      rails (>= 4.0.0)
    bootstrap-sass (3.3.7)
      autoprefixer-rails (>= 5.2.1)
      sass (>= 3.3.4)
    breadcrumbs_on_rails (3.0.1)
    browser (2.5.3)
    builder (3.2.3)
    cancancan (1.17.0)
    capistrano (3.10.2)
      airbrussh (>= 1.0.0)
      i18n
      rake (>= 10.0.0)
      sshkit (>= 1.9.0)
    capistrano-bundler (1.3.0)
      capistrano (~> 3.1)
      sshkit (~> 1.2)
    capistrano-rails (1.1.8)
      capistrano (~> 3.1)
      capistrano-bundler (~> 1.1)
    capistrano-rbenv (2.1.3)
      capistrano (~> 3.1)
      sshkit (~> 1.3)
    capybara (3.1.0)
      addressable
      mini_mime (>= 0.1.3)
      nokogiri (~> 1.8)
      rack (>= 1.6.0)
      rack-test (>= 0.6.3)
      xpath (~> 3.0)
    carrierwave (1.2.2)
      activemodel (>= 4.0.0)
      activesupport (>= 4.0.0)
      mime-types (>= 1.16)
    charlock_holmes (0.7.6)
    childprocess (0.9.0)
      ffi (~> 1.0, >= 1.0.11)
    chronic (0.10.2)
    code_analyzer (0.4.8)
      sexp_processor
    coderay (1.1.2)
    coffee-rails (4.2.2)
      coffee-script (>= 2.2.0)
      railties (>= 4.0.0)
    coffee-script (2.4.1)
      coffee-script-source
      execjs
    coffee-script-source (1.12.2)
    colorize (0.8.1)
    concurrent-ruby (1.0.5)
    crass (1.0.4)
    daemons (1.2.6)
    database_cleaner (1.7.0)
    delayed_job (4.1.5)
      activesupport (>= 3.0, < 5.3)
    delayed_job_active_record (4.1.3)
      activerecord (>= 3.0, < 5.3)
      delayed_job (>= 3.0, < 5)
    devise (4.4.3)
      bcrypt (~> 3.0)
      orm_adapter (~> 0.1)
      railties (>= 4.1.0, < 6.0)
      responders
      warden (~> 1.2.3)
    devise-security (0.12.0)
      devise (>= 4.2.0, < 5.0)
      rails (>= 4.1.0, < 6.0)
    diff-lcs (1.3)
    docile (1.3.0)
    erubi (1.7.1)
    erubis (2.7.0)
    eventmachine (1.2.7)
    execjs (2.7.0)
    factory_bot (4.8.2)
      activesupport (>= 3.0.0)
    faker (1.8.7)
      i18n (>= 0.7)
    ffi (1.9.23)
    font-awesome-rails (4.7.0.4)
      railties (>= 3.2, < 6.0)
    font-ionicons-rails (2.0.1.5)
      railties (>= 3.2, < 6.0)
    gherkin-ruby (0.3.2)
    globalid (0.4.1)
      activesupport (>= 4.2.0)
    haml (5.0.4)
      temple (>= 0.8.0)
      tilt
    haml-rails (1.0.0)
      actionpack (>= 4.0.1)
      activesupport (>= 4.0.1)
      haml (>= 4.0.6, < 6.0)
      html2haml (>= 1.0.1)
      railties (>= 4.0.1)
    html2haml (2.2.0)
      erubis (~> 2.7.0)
      haml (>= 4.0, < 6)
      nokogiri (>= 1.6.0)
      ruby_parser (~> 3.5)
    htmlentities (4.3.4)
    i18n (0.9.5)
      concurrent-ruby (~> 1.0)
    i18n-js (3.0.5)
      i18n (>= 0.6.6, < 2)
    jbuilder (2.7.0)
      activesupport (>= 4.2.0)
      multi_json (>= 1.2)
    jquery-datatables-rails (3.4.0)
      actionpack (>= 3.1)
      jquery-rails
      railties (>= 3.1)
      sass-rails
    jquery-rails (4.3.3)
      rails-dom-testing (>= 1, < 3)
      railties (>= 4.2.0)
      thor (>= 0.14, < 2.0)
    jquery-turbolinks (2.1.0)
      railties (>= 3.1.0)
      turbolinks
    jquery-ui-rails (6.0.1)
      railties (>= 3.2.16)
    json (1.8.6)
    kaminari (1.1.1)
      activesupport (>= 4.1.0)
      kaminari-actionview (= 1.1.1)
      kaminari-activerecord (= 1.1.1)
      kaminari-core (= 1.1.1)
    kaminari-actionview (1.1.1)
      actionview
      kaminari-core (= 1.1.1)
    kaminari-activerecord (1.1.1)
      activerecord
      kaminari-core (= 1.1.1)
    kaminari-core (1.1.1)
    kgio (2.11.2)
    loofah (2.2.2)
      crass (~> 1.0.2)
      nokogiri (>= 1.5.9)
    mail (2.7.0)
      mini_mime (>= 0.1.1)
    mailcatcher (0.2.4)
      eventmachine
      haml
      i18n
      json
      mail
      sinatra
      skinny (>= 0.1.2)
      sqlite3-ruby
      thin
    marcel (0.3.2)
      mimemagic (~> 0.3.2)
    method_source (0.9.0)
    mime-types (3.1)
      mime-types-data (~> 3.2015)
    mime-types-data (3.2016.0521)
    mimemagic (0.3.2)
    mini_mime (1.0.0)
    mini_portile2 (2.3.0)
    minitest (5.11.3)
    multi_json (1.13.1)
    mustermann (1.0.2)
    net-scp (1.2.1)
      net-ssh (>= 2.6.5)
    net-ssh (4.2.0)
    nio4r (2.3.1)
    nokogiri (1.8.2)
      mini_portile2 (~> 2.3.0)
    orm_adapter (0.5.0)
    parser (2.5.1.0)
      ast (~> 2.4.0)
    pdf-core (0.7.0)
    pdfjs_rails (0.0.1)
    pg (0.21.0)
    powerpack (0.1.1)
    prawn (2.2.2)
      pdf-core (~> 0.7.0)
      ttfunk (~> 1.5)
    prawn-table (0.2.2)
      prawn (>= 1.3.0, < 3.0.0)
    pry (0.11.3)
      coderay (~> 1.1.0)
      method_source (~> 0.9.0)
    pry-rails (0.3.6)
      pry (>= 0.10.4)
    public_activity (1.4.3)
      actionpack (>= 3.0.0)
      activerecord (>= 3.0)
      i18n (>= 0.5.0)
      railties (>= 3.0.0)
    public_suffix (3.0.2)
    rack (2.0.5)
    rack-accept (0.4.5)
      rack (>= 0.4)
    rack-mini-profiler (1.0.0)
      rack (>= 1.2.0)
    rack-protection (2.0.1)
      rack
    rack-test (1.0.0)
      rack (>= 1.0, < 3)
    rails (5.2.0)
      actioncable (= 5.2.0)
      actionmailer (= 5.2.0)
      actionpack (= 5.2.0)
      actionview (= 5.2.0)
      activejob (= 5.2.0)
      activemodel (= 5.2.0)
      activerecord (= 5.2.0)
      activestorage (= 5.2.0)
      activesupport (= 5.2.0)
      bundler (>= 1.3.0)
      railties (= 5.2.0)
      sprockets-rails (>= 2.0.0)
    rails-dom-testing (2.0.3)
      activesupport (>= 4.2.0)
      nokogiri (>= 1.6)
    rails-html-sanitizer (1.0.4)
      loofah (~> 2.2, >= 2.2.2)
    rails_best_practices (1.19.2)
      activesupport
      code_analyzer (>= 0.4.8)
      erubis
      i18n
      json
      require_all (~> 2.0)
      ruby-progressbar
    railties (5.2.0)
      actionpack (= 5.2.0)
      activesupport (= 5.2.0)
      method_source
      rake (>= 0.8.7)
      thor (>= 0.18.1, < 2.0)
    rainbow (2.2.2)
      rake
    raindrops (0.19.0)
    rake (12.3.1)
    ranked-model (0.4.0)
      activerecord (>= 3.1.12)
    rb-fsevent (0.10.3)
    rb-inotify (0.9.10)
      ffi (>= 0.5.0, < 2)
    rdoc (4.3.0)
    rename (1.0.6)
      activesupport
      rails (>= 3.0.0)
      thor (>= 0.19.1)
    require_all (2.0.0)
    responders (2.4.0)
      actionpack (>= 4.2.0, < 5.3)
      railties (>= 4.2.0, < 5.3)
    rspec-core (3.7.1)
      rspec-support (~> 3.7.0)
    rspec-expectations (3.7.0)
      diff-lcs (>= 1.2.0, < 2.0)
      rspec-support (~> 3.7.0)
    rspec-mocks (3.7.0)
      diff-lcs (>= 1.2.0, < 2.0)
      rspec-support (~> 3.7.0)
    rspec-rails (3.7.2)
      actionpack (>= 3.0)
      activesupport (>= 3.0)
      railties (>= 3.0)
      rspec-core (~> 3.7.0)
      rspec-expectations (~> 3.7.0)
      rspec-mocks (~> 3.7.0)
      rspec-support (~> 3.7.0)
    rspec-support (3.7.1)
    rubocop (0.40.0)
      parser (>= 2.3.1.0, < 3.0)
      powerpack (~> 0.1)
      rainbow (>= 1.99.1, < 3.0)
      ruby-progressbar (~> 1.7)
      unicode-display_width (~> 1.0, >= 1.0.1)
    ruby-progressbar (1.9.0)
    ruby_parser (3.11.0)
      sexp_processor (~> 4.9)
    rubyzip (1.0.0)
    sass (3.5.6)
      sass-listen (~> 4.0.0)
    sass-listen (4.0.0)
      rb-fsevent (~> 0.9, >= 0.9.4)
      rb-inotify (~> 0.9, >= 0.9.7)
    sass-rails (5.0.7)
      railties (>= 4.0.0, < 6)
      sass (~> 3.1)
      sprockets (>= 2.8, < 4.0)
      sprockets-rails (>= 2.0, < 4.0)
      tilt (>= 1.1, < 3)
    sdoc (0.4.2)
      json (~> 1.7, >= 1.7.7)
      rdoc (~> 4.0)
    selenium-webdriver (3.8.0)
      childprocess (~> 0.5)
      rubyzip (~> 1.0)
    settingslogic (2.0.9)
    sexp_processor (4.11.0)
    simple_form (4.0.0)
      actionpack (> 4)
      activemodel (> 4)
    simplecov (0.16.1)
      docile (~> 1.1)
      json (>= 1.8, < 3)
      simplecov-html (~> 0.10.0)
    simplecov-html (0.10.2)
    sinatra (2.0.1)
      mustermann (~> 1.0)
      rack (~> 2.0)
      rack-protection (= 2.0.1)
      tilt (~> 2.0)
    skinny (0.2.2)
      eventmachine (~> 1.0)
      thin
    spinach (0.10.1)
      colorize
      gherkin-ruby (>= 0.3.2)
      json
    spinach-rails (0.2.1)
      capybara (>= 2.0.0)
      railties (>= 3)
      spinach (>= 0.4)
    spring (2.0.2)
      activesupport (>= 4.2)
    sprockets (3.7.1)
      concurrent-ruby (~> 1.0)
      rack (> 1, < 3)
    sprockets-rails (3.2.1)
      actionpack (>= 4.0)
      activesupport (>= 4.0)
      sprockets (>= 3.0.0)
    sqlite3 (1.3.13)
    sqlite3-ruby (1.3.3)
      sqlite3 (>= 1.3.3)
    sshkit (1.16.0)
      net-scp (>= 1.1.2)
      net-ssh (>= 2.8.0)
    temple (0.8.0)
    thin (1.7.2)
      daemons (~> 1.0, >= 1.0.9)
      eventmachine (~> 1.0, >= 1.0.4)
      rack (>= 1, < 3)
    thor (0.20.0)
    thread_safe (0.3.6)
    tilt (2.0.8)
    ttfunk (1.5.1)
    turbolinks (5.1.1)
      turbolinks-source (~> 5.1)
    turbolinks-source (5.1.0)
    turnout (2.4.1)
      i18n (~> 0.7)
      rack (>= 1.3, < 3)
      rack-accept (~> 0.4)
      tilt (>= 1.4, < 3)
    tzinfo (1.2.5)
      thread_safe (~> 0.1)
    uglifier (4.1.10)
      execjs (>= 0.3.0, < 3)
    unicode-display_width (1.3.2)
    unicorn (5.4.0)
      kgio (~> 2.6)
      raindrops (~> 0.7)
    warden (1.2.7)
      rack (>= 1.0)
    websocket-driver (0.7.0)
      websocket-extensions (>= 0.1.0)
    websocket-extensions (0.1.3)
    whenever (0.10.0)
      chronic (>= 0.6.3)
    xpath (3.0.0)
      nokogiri (~> 1.8)
    yard (0.9.12)

PLATFORMS
  ruby

DEPENDENCIES
  ajax-datatables-rails (~> 0.4.0)
  autoprefixer-rails
  axlsx (~> 2.0)
  axlsx_rails
  bootstrap-datepicker-rails!
  bootstrap-kaminari-views
  bootstrap-multiselect-rails
  bootstrap-sass (~> 3.3.1)
  breadcrumbs_on_rails
  browser
  cancancan (~> 1.10)
  capistrano (~> 3.5)
  capistrano-bundler
  capistrano-rails (~> 1.1.0)
  capistrano-rbenv (~> 2.0)
  capybara
  carrierwave
  charlock_holmes
  coffee-rails
  database_cleaner
  delayed_job_active_record
  devise
  devise-security
  factory_bot
  faker
  font-awesome-rails
  font-ionicons-rails
  haml-rails
  i18n-js (>= 3.0.0.rc11)
  jbuilder (~> 2.0)
  jquery-datatables-rails
  jquery-rails
  jquery-turbolinks
  jquery-ui-rails
  kaminari
  mailcatcher
  nested_form!
  pdfjs_rails
  pg (= 0.21.0)
  prawn
  prawn-table
  pry-rails
  public_activity (~> 1.4.1)
  rack-mini-profiler
  rails (= 5.2.0)
  rails_best_practices
  ranked-model
  rename
  rspec-rails
  rubocop (~> 0.40.0)
  rubyzip
  sass-rails
  sdoc (~> 0.4.0)
  selenium-webdriver
  settingslogic
  simple_form
  simplecov
  spinach-rails
  spring
  turnout
  uglifier (>= 1.3.0)
  unicorn
  whenever
  yard

BUNDLED WITH
   1.16.1
n-rodriguez commented 6 years ago

The lambda takes 2 params : https://github.com/jbox-web/ajax-datatables-rails/blob/v0.4.x/lib/ajax-datatables-rails/datatable/column/search.rb#L20

reiallenramos commented 6 years ago

I'm not sure which part I should modify..

n-rodriguez commented 6 years ago
  def filter_full_name_condition
    ->(column, value) { column.table[column.field].eq(column.search.value.to_i + 1) }
  end
reiallenramos commented 6 years ago

Ah you're a lifesaver! Thank you so much :)

n-rodriguez commented 6 years ago

You're welcome!