Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions .rvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/usr/bin/env bash

# This is an RVM Project .rvmrc file, used to automatically load the ruby
# development environment upon cd'ing into the directory

# First we specify our desired <ruby>[@<gemset>], the @gemset name is optional,
# Only full ruby name is supported here, for short names use:
# echo "rvm use 1.9.3" > .rvmrc
environment_id="ruby-1.9.3-p125@ajax-datatables-rails"

# Uncomment the following lines if you want to verify rvm version per project
# rvmrc_rvm_version="1.11.0-pre" # 1.10.1 seams as a safe start
# eval "$(echo ${rvm_version}.${rvmrc_rvm_version} | awk -F. '{print "[[ "$1*65536+$2*256+$3" -ge "$4*65536+$5*256+$6" ]]"}' )" || {
# echo "This .rvmrc file requires at least RVM ${rvmrc_rvm_version}, aborting loading."
# return 1
# }

# First we attempt to load the desired environment directly from the environment
# file. This is very fast and efficient compared to running through the entire
# CLI and selector. If you want feedback on which environment was used then
# insert the word 'use' after --create as this triggers verbose mode.
if [[ -d "${rvm_path:-$HOME/.rvm}/environments"
&& -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]]
then
\. "${rvm_path:-$HOME/.rvm}/environments/$environment_id"
[[ -s "${rvm_path:-$HOME/.rvm}/hooks/after_use" ]] &&
\. "${rvm_path:-$HOME/.rvm}/hooks/after_use" || true
else
# If the environment file has not yet been created, use the RVM CLI to select.
rvm --create "$environment_id" || {
echo "Failed to create RVM environment '${environment_id}'."
return 1
}
fi

# If you use bundler, this might be useful to you:
# if [[ -s Gemfile ]] && {
# ! builtin command -v bundle >/dev/null ||
# builtin command -v bundle | grep $rvm_path/bin/bundle >/dev/null
# }
# then
# printf "%b" "The rubygem 'bundler' is not installed. Installing it now.\n"
# gem install bundler
# fi
# if [[ -s Gemfile ]] && builtin command -v bundle >/dev/null
# then
# bundle install | grep -vE '^Using|Your bundle is complete'
# fi
2 changes: 0 additions & 2 deletions ajax-datatables-rails.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,4 @@ Gem::Specification.new do |gem|
gem.name = "ajax-datatables-rails"
gem.require_paths = ["lib"]
gem.version = AjaxDatatablesRails::VERSION

gem.add_runtime_dependency 'jquery-datatables-rails', '~> 1.9.1'
end
26 changes: 6 additions & 20 deletions lib/ajax-datatables-rails.rb
Original file line number Diff line number Diff line change
@@ -1,28 +1,14 @@
require 'rails'
# require 'rails'

class AjaxDatatablesRails

VERSION = '0.0.1'

class << self

def columns(column_array)
@@columns ||= column_array
end

def model_name(model_name)
@@model_name ||= model_name
end

def searchable_columns(columns_array)
@@searchable_columns ||= columns_array
end

end

def initialize(view)
@view = view
end

attr_reader :columns, :model_name, :searchable_columns

def method_missing(meth, *args, &block)
@view.send(meth, *args, &block)
Expand All @@ -31,7 +17,7 @@ def method_missing(meth, *args, &block)
def as_json(options = {})
{
sEcho: params[:sEcho].to_i,
iTotalRecords: @@model_name.count,
iTotalRecords: @model_name.count,
iTotalDisplayRecords: get_raw_records.count,
aaData: data
}
Expand All @@ -57,7 +43,7 @@ def sort_records(records)

def search_records(records)
if params[:sSearch].present?
query = @@searchable_columns.map do |column|
query = @searchable_columns.map do |column|
"#{column} LIKE :search"
end.join(" OR ")
records = records.where(query, search: "%#{params[:sSearch]}%")
Expand All @@ -74,7 +60,7 @@ def per_page
end

def sort_column
@@columns[params[:iSortCol_0].to_i]
@columns[params[:iSortCol_0].to_i]
end

def sort_direction
Expand Down
12 changes: 8 additions & 4 deletions lib/generators/ajaxdatatable/templates/datatable.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
class <%= model.classify %>Datatable < AjaxDatatableRails
model_name <%= model.classify %>
columns # insert array of column names here
searchable_columns #insert array of columns that will be searched
class <%= model.classify.pluralize %>Datatable < AjaxDatatablesRails

def initialize(view)
@model_name = <%= model.classify %>
@columns = # insert array of column names here
@searchable_columns = #insert array of columns that will be searched
super(view)
end

private

Expand Down
3 changes: 0 additions & 3 deletions lib/generators/datatable_generator.rb

This file was deleted.