I have a JSON API based on Rails 5. I have a method that brings list of all the products for one particular company, which I want to paginate so that not to bring up all the data at once. For this I came across two gems, namely will_paginate and api-pagination.
After running bundle install and restarting the server, I'm still getting the following error :
NoMethodError (undefined method `paginate' for #<Api::V1::ProductsController:0x007fb25404db30>)
The Products Controller :
require 'roo'
class Api::V1::ProductsController < ApplicationController
respond_to :json
def index
comp_id = params[:company_id]
cat_id = params[:category_id]
if comp_id
if comp_id && cat_id
product = Product.where(:company_id => comp_id, :category_id => cat_id)
else
product = Product.where(:company_id => comp_id)
end
paginate json: product, status: 200
else
render json: { errors: "Company ID is NULL" }, status: 422
end
end
end
Gemfile.rb
source 'https://rubygems.org'
git_source(:github) do |repo_name|
repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/")
"https://github.com/#{repo_name}.git"
end
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 5.0.2'
# Use mysql as the database for Active Record
gem 'mysql2', '>= 0.3.18', '< 0.5'
# Use Puma as the app server
gem 'puma', '~> 3.0'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.2'
# See https://github.com/rails/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby
# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
gem 'turbolinks', '~> 5'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.5'
#Devise Gem for Authentication
gem "devise"
#For JSON Serialization
gem 'active_model_serializers'
# Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 3.0'
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'
gem 'carrierwave'
gem 'roo'
#For Pagination
gem 'will_paginate'
gem 'api-pagination'
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug', platform: :mri
end
group :development do
# Access an IRB console on exception pages or by using <%= console %> anywhere in the code.
gem 'web-console', '>= 3.3.0'
gem 'listen', '~> 3.0.5'
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'
gem 'spring-watcher-listen', '~> 2.0.0'
# Use Capistrano for deployment
gem 'capistrano', group: :development
gem 'capistrano-rails', group: :development
gem 'capistrano3-puma', group: :development
end
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
Can someone tell me where I'm going wrong?
Try to make sure your ApplicationController inherits from ActionController::API instead of ActionController::Base. And if for some reason you can't update your controller, you can include the Rails::Pagination module into your ApplicationController manually.
credits
Update:
class ApplicationController
include Rails::Pagination
......
....
end
Related
I'm running spree version 4.0.2 on Rails 6.0.2.1 and I've encountered the following error when I try to login or logout:
ActionView::Template::Error (PG::UndefinedColumn: ERROR: column spree_orders.guest_token does not exist
LINE 1: ...t" IS NULL AND "spree_orders"."currency" = $1 AND "spree_ord...
^
):
10: <ul class="nav navbar-right" data-hook>
11: <li id="link-to-cart" class="nav-item" data-hook>
12: <noscript>
13: <%= link_to_cart %>
14: </noscript>
15: Â
16: </li>
I know that the problem is that a query is being generated somewhere when link-to-cart is executed that refers to the column column guest_token which was changed to token in a migration. My Gemfile is shown below.
Can anyone help me with this? I'm relatively new to ruby, rails, and spree, so if I've left out important information, please let me know.
Thanks in advance!
Jeff
source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
ruby '2.6.5'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 6.0.0'
# Use sqlite3 as the database for Active Record
gem 'pg'
# Use Puma as the app server
gem 'puma', '~> 3.11'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5'
# Transpile app-like JavaScript. Read more: https://github.com/rails/webpacker
gem 'webpacker', '~> 4.0'
# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
gem 'turbolinks', '~> 5'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.7'
# Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 4.0'
# Use Active Model has_secure_password
# gem 'bcrypt', '~> 3.1.7'
# Use Active Storage variant
# gem 'image_processing', '~> 1.2'
# Reduces boot times through caching; required in config/boot.rb
gem 'bootsnap', '>= 1.4.2', require: false
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
end
group :development do
# Access an interactive console on exception pages or by calling 'console' anywhere in the code.
gem 'web-console', '>= 3.3.0'
gem 'listen', '>= 3.0.5', '< 3.2'
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'
gem 'spring-watcher-listen', '~> 2.0.0'
end
group :test do
# Adds support for Capybara system testing and selenium driver
gem 'capybara', '>= 2.15'
gem 'selenium-webdriver'
# Easy installation and use of web drivers to run system tests with browsers
gem 'webdrivers'
end
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
gem 'spree', '~> 4.0'
gem 'spree_auth_devise', '~> 4.0'
gem 'spree_gateway', '~> 3.6'
gem 'aws-sdk-s3', require: false
#gem "google-cloud-storage", "~> 1.11", require: false
gem 'spree_braintree_vzero', github: 'spree-contrib/spree_braintree_vzero'
gem 'spree_i18n', :github => 'spree/spree_i18n'
gem 'spree_globalize', github: 'spree-contrib/spree_globalize'
gem 'activerecord-nulldb-adapter'
For me it seemed to be spree_braintree_vzero gem.
Maybe it doesn't work with the latest Spree v4 ?
How to Uninstall and Remove Spree Braintree VZero
It may be useful to see what the install script is doing here:
https://github.com/spree-contrib/spree_braintree_vzero/blob/master/lib/generators/spree_braintree_vzero/install/install_generator.rb
To uninstall spree_braintree_vzero I had to do the following.
Remove the Gem from Gemfile
gem 'spree_braintree_vzero', github: 'spree-contrib/spree_braintree_vzero'
Remove all.js changes
vendor/assets/javascripts/spree/backend/all.js (git)
//= require spree/backend/spree_braintree_vzero
vendor/assets/javascripts/spree/frontend/all.js
//= require spree/frontend/spree_braintree_vzero
Delete config/schedule.rb
Yep that is all. Unless it existed before you ran the installer.
You can remove it if all it has in it is rake 'spree_braintree_vzero:update_states', otherwise remove that line from it and the surrounding blocks.
Example: https://github.com/spree-contrib/spree_braintree_vzero/blob/1bc400bb598bf177edfe614aef44fcd28eca2312/lib/generators/spree_braintree_vzero/install/install_generator.rb#L15
Add Migrations to Revert Migrations
Note: These could change so check your logs for what you did when you added it.
PS: Don't worry about migrations that touched on the spree_braintree_checkout table since it's going to be dropped.
Protip: don't forget to run your migrations ;)
class DropSpreeBraintreeCheckouts < ActiveRecord::Migration[6.0]
def up
drop_table :spree_braintree_checkouts
end
def down
raise ActiveRecord::IrreversibleMigration
end
end
class RemoveBraintreeIdFromSpreeAddresses < ActiveRecord::Migration[6.0]
def change
remove_column :spree_addresses, :braintree_id
end
end
class RemoveBraintreeTokenAndNonceFromSpreePayments < ActiveRecord::Migration[6.0]
def change
remove_column :spree_payments, :braintree_token
remove_column :spree_payments, :braintree_nonce
end
end
In my rails app I am priting receipt using cups with gem cupsffi
This is the job I have set:
class PrintReceiptJob < ActiveJob::Base
require 'cupsffi'
printers = CupsPrinter.get_all_printer_names
printer = CupsPrinter.new(printers.first)
job = printer.print_file(Rails.root.join('receipt.pdf').to_s, {'PageSize' => 'A4'})
end
In my controller I generate the receipt in pdf with prawn and call the job above:
pdf = ReceiptPdf.new(#receipt)
pdf.render_file "receipt.pdf"
PrintReceiptJob.perform_now
And it works, the receipt gets printed.
Problem is, after printing I get this error:
[ActiveJob] [PrintReceiptJob] [044c6b97-daca-445d-9c87-631e3de3d7cd] Performing PrintReceiptJob (Job ID: 044c6b97-daca-445d-9c87-631e3de3d7cd) from Async(default)
[ActiveJob] [PrintReceiptJob] [044c6b97-daca-445d-9c87-631e3de3d7cd] Error performing PrintReceiptJob (Job ID: 044c6b97-daca-445d-9c87-631e3de3d7cd) from Async(default) in 0.52ms: NotImplementedError (NotImplementedError):
For what I understand it's trying to perform the job twice, and second time it fails.
application.rb
require_relative 'boot'
require 'apartment/elevators/subdomain'
require 'rails/all'
require File.expand_path('../boot', __FILE__)
ENV['RANSACK_FORM_BUILDER'] = '::SimpleForm::FormBuilder'
# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups)
module CompanyManagement
class Application < Rails::Application
# Initialize configuration defaults for originally generated Rails version.
config.load_defaults 5.2
config.time_zone = "Singapore"
end
end
Gemfile:
source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
ruby '2.5.1'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 5.2.0'
# Use mysql as the database for Active Record
gem 'mysql2', '>= 0.4.4', '< 0.6.0'
# Use Puma as the app server
gem 'puma', '~> 3.11'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# See https://github.com/rails/execjs#readme for more supported runtimes
gem 'mini_racer', platforms: :ruby
# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.2'
# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
gem 'turbolinks', '~> 5'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.5'
# Use Redis adapter to run Action Cable in production
#gem 'redis', '~> 4.0'
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'
# Use ActiveStorage variant
# gem 'mini_magick', '~> 4.8'
# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development
# Reduces boot times through caching; required in config/boot.rb
gem 'bootsnap', '>= 1.1.0', require: false
gem 'devise'
gem 'bootstrap'
gem 'jquery-ui-rails'
gem 'jquery-rails'
gem 'simple_form'
gem "font-awesome-rails"
gem "cocoon"
gem "select2-rails"
gem 'will_paginate'
gem 'will_paginate-bootstrap4'
gem "chartkick"
gem 'groupdate'
gem 'trix-rails', require: 'trix'
gem 'amoeba'
gem "simple_calendar", "~> 2.0"
gem 'apartment'
gem 'protokoll'
gem 'ransack'
gem "time_splitter"
gem 'working_hours'
gem 'jquery-minicolors-rails'
gem 'carrierwave', '~> 1.0'
gem 'prawn-rails'
gem 'cupsffi'
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
end
group :development do
# Access an interactive console on exception pages or by calling 'console' anywhere in the code.
gem 'web-console', '>= 3.3.0'
gem 'listen', '>= 3.0.5', '< 3.2'
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'
gem 'spring-watcher-listen', '~> 2.0.0'
gem 'pry'
end
group :test do
# Adds support for Capybara system testing and selenium driver
gem 'capybara', '>= 2.15', '< 4.0'
gem 'selenium-webdriver'
# Easy installation and use of chromedriver to run system tests with Chrome
gem 'chromedriver-helper'
end
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
What am I missing? How can I fix?
You forgot to wrap your code with method:
require 'cupsffi'
class PrintReceiptJob < ActiveJob::Base
def perform
printers = CupsPrinter.get_all_printer_names
printer = CupsPrinter.new(printers.first)
job = printer.print_file(Rails.root.join('receipt.pdf').to_s, {'PageSize' => 'A4'})
end
end
I'm currently trying to deploy my blog using Dokku. I've been following the guides on how to deploy using Dokku, but it wasn't until I got to start deploying the application, I ran into an HTTP Error. I've been using a Mac to develop my blog.
Here's my gem file that I'm using:
source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
ruby '2.5.1'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 5.2.0'
# Use Puma as the app server
gem 'puma', '~> 3.11'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# See https://github.com/rails/execjs#readme for more supported runtimes
# gem 'mini_racer', platforms: :ruby
gem "loofah", ">= 2.2.3"
# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.2'
# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
gem 'turbolinks', '~> 5'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.5'
# Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 4.0'
# Use ActiveModel has_secure_password
gem 'bcrypt', '~> 3.1.7'
# Use Bulma Rails to simply the CSS part of the site
gem "bulma-rails", "~> 0.7.1"
# Using font-awesome to get icons from font-awesome
gem "font-awesome-rails", '~> 4.7', '>= 4.7.0.4'
gem 'font-awesome-sass', '~> 5.5'
# Use Simple for Authentication
gem 'simple_form', '~> 4.0.0'
# FriendlyID
gem 'friendly_id', '~> 5.1.0'
# ACME-CLIENT
gem 'acme-client', '~> 2.0', '>= 2.0.1'
gem 'nokogiri', '~> 1.8', '>= 1.8.5'
gem 'sassc', '~> 1.12', '>= 1.12.1'
# Use ActiveStorage variant
gem 'mini_magick', '~> 4.8'
# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development
# Adds likes to comments and blog posts.
gem 'acts_as_votable', '~> 0.11.1'
#Devise - Authnetication Gem
gem 'devise', '~> 4.4', '>= 4.4.3'
#Pundit - Authorization Gem
gem 'pundit', '~> 1.1'
#CKEditor - To make my textarea and blog posts more robust
gem 'ckeditor', '~> 4.2', '>= 4.2.4', github: 'galetahub/ckeditor'
# Reduces boot times through caching; required in config/boot.rb
gem 'bootsnap', '>= 1.1.0', require: false
gem 'carrierwave', '~> 1.0'
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
# Call Rspec to test applications
gem 'rspec-rails', '~> 3.7'
#Factory Bot Rails
gem 'factory_bot_rails', '~> 4.7'
end
group :development do
# Access an interactive console on exception pages or by calling 'console' anywhere in the code.
gem 'web-console', '>= 3.3.0'
gem 'listen', '>= 3.0.5', '< 3.2'
# Use the better errors gem to better locate stack trace errors.
gem "better_errors"
#binding-of-caller
gem 'binding_of_caller', '~> 0.8.0'
# Guard is used to simplify running the server
gem 'guard'
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'
gem 'spring-watcher-listen', '~> 2.0.0'
# Automatically resets the server upon change the view.
gem 'guard-livereload', '~> 2.5', '>= 2.5.2', require: false
gem 'rb-readline'
gem "letter_opener"
end
group :test do
# Adds support for Capybara system testing and selenium driver
gem 'capybara', '>= 2.15', '< 4.0'
gem 'selenium-webdriver'
#Database Cleaner - Used to clean the database upon finishing a test.
gem 'database_cleaner'
# Easy installation and use of chromedriver to run system tests with Chrome
gem 'chromedriver-helper'
end
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
gem 'pg'
# Require bootstrap
gem 'bootstrap', '~> 4.1.1'
#jQuery for Rails!
gem 'jquery-rails', '~> 4.3', '>= 4.3.3'
#Pagination for the site (Note: "kaminari" is Japanese for lightning.)
gem 'kaminari', '~> 1.1', '>= 1.1.1'
I also found some issue that Bundler 2.0.1 doesn't seem to work. If there's else like a code snippet that you may need to solve the issue, please let me know. Thanks.
Edit: Here's my Application Controller
class ApplicationController < ActionController::Base
include Pundit
rescue_from Pundit::NotAuthorizedError, with: :user_not_authorized
protect_from_forgery with: :exception
before_action :configure_permitted_parameters, if: :devise_controller?
protected
def configure_permitted_parameters
added_attrs = [ :username, :email, :password, :password_confirmation ]
devise_parameter_sanitizer.permit :sign_up, keys: added_attrs
devise_parameter_sanitizer.permit :account_update, keys: added_attrs
devise_parameter_sanitizer.permit :sign_in, keys: added_attrs
end
private
def user_not_authorized
flash[:alert] = "You aren't authorized to go to that page. Contact TheBigL through email at master_biglee#live.ca."
redirect_to (request.referrer || root_path)
end
end
Edit: Here's my config/application.rb file
require_relative 'boot'
require 'rails/all'
# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups)
module Blog
class Application < Rails::Application
# Initialize configuration defaults for originally generated Rails version.
config.load_defaults 5.2
# Settings in config/environments/* take precedence over those specified here.
# Application configuration can go into files in config/initializers
# -- all .rb files in that directory are automatically loaded after loading
# the framework and any gems in your application.
end
end
Have a Ruby on Rails app with carrierwave and imagemagick for image upload. In my app, when I click to save record with the image upload, get an error "Image translation missing: en.errors.messages.mini_magick_processing_error". Seeing this on a Heroku deploy. I had this issue on both my local machine and on cloud9 Rails instance, which I resolved by manually running install of imagemagick. Not sure how I would do that on heroku.
Welcome comments, questions, suggestions.
Gemfile contents below -
source 'https://rubygems.org'
git_source(:github) do |repo_name|
repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/")
"https://github.com/#{repo_name}.git"
end
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 5.0.1'
# Use sqlite3 as the database for Active Record
#gem 'sqlite3'
# Use Puma as the app server
gem 'puma', '~> 3.0'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.2'
# See https://github.com/rails/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby
# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
gem 'turbolinks', '~> 5'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.5'
# Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 3.0'
# Use ActiveModel has_secure_password
gem 'bcrypt', '~> 3.1.7'
# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development
gem 'carrierwave'
gem 'mini_magick'
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug', platform: :mri
gem 'sqlite3'
end
group :development do
# Access an IRB console on exception pages or by using <%= console %> anywhere in the code.
gem 'web-console', '>= 3.3.0'
gem 'listen', '~> 3.0.5'
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'
gem 'spring-watcher-listen', '~> 2.0.0'
end
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
group :production do
gem 'pg', '0.20.0'
end
I can not add gem best_in_place to my table.
class_datatable.rb:
def data
class.map do |record|
[
best_in_place(record, :name),
best_in_place(record, :short_name)
]
end
end
There is an error: NoMethodError (undefined method `best_in_place' for ClassDatatable:0xa9283a44)
My gem file:
source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.2.4'
# Use sqlite3 as the database for Active Record
gem 'ruby-oci8'
gem 'activerecord-oracle_enhanced-adapter'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.1.0'
# See https://github.com/rails/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby
# Use jquery as the JavaScript library
gem 'jquery-rails'
gem 'jquery-turbolinks'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.0'
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 0.4.0', group: :doc
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'
# Use Unicorn as the app server
# gem 'unicorn'
# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development
#---------------------------------My gems--------------------------------------------------------
#Twitter Bootstrap
gem "therubyracer"
gem "less-rails" #Sprockets (what Rails 3.1 uses for its asset pipeline) supports LESS
gem "twitter-bootstrap-rails"
gem 'client_side_validations'
#Datatables
gem 'jquery-datatables-rails', '~> 1.12.2'
gem 'font-awesome-rails' # Icons
gem 'foundation-rails' # zurb foundation
#Best in place
gem 'best_in_place'
#Russian langue
gem 'russian', '~> 0.6.0'
#Jquery UI
gem 'jquery-ui-rails'
#Paginate
gem 'will_paginate'
#-----------------------------------end---------------------------------------------------------
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug'
end
group :development do
# Access an IRB console on exception pages or by using <%= console %> in views
gem 'web-console', '~> 2.0'
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'
end
Bundle install is done!
If I do like this on the page:
<% Class.all.each do |record| %>
<%= best_in_place(record, :name) %>
<% end %>
That works.
However, the method does not work "def data"
Understood!
It was necessary to add delegate best_in_place section at the beginning of the file class_datatable.rb
For anyone struggling to find the right way to delegate, this is how it is done:
class MyCustomDatatable < AjaxDatatablesRails::Base
# either define them one-by-one
def_delegator :#view, :link_to
def_delegator :#view, :h
def_delegator :#view, :mail_to
# or define them in one pass
def_delegators :#view, :link_to, :h, :mailto, :edit_resource_path, :other_method
# now, you'll have these methods available to be used anywhere
# example: mapping the 2d jsonified array returned.
def data
records.map do |record|
[
link_to(record.fname, edit_resource_path(record)),
mail_to(record.email),
# other attributes
]
end
end
end
Source: https://github.com/antillas21/ajax-datatables-rails#using-view-helpers