Not getting RAILS ActiveRecord::Relation returned - ruby-on-rails-3

I am running RAILS 3.0.9, and for the life of me, I can not get RAILS to do the new lazy loading.
My gemfile is:
gem 'rails', '3.0.9'
gem 'sqlite3'
gem 'nifty-generators', '>= 0.4.6'
gem 'mocha', :group => :test
gem 'carrierwave'
gem 'rmagick'
gem 'devise', '1.1.rc0'
gem 'jquery-rails', '>= 1.0.3'
And if I do:
Period.where("id=1")
I get:
[#<Period id: 1, start: "2011-07-06", end: "2011-07-13", created_at: "2011-07-06 23:01:46", updated_at: "2011-07-06 23:01:46"]
I really need it to do the ActiveRecord::Relation thing instead! Anyone know what's going on?

You are doing the ActiveRecord::Relation thing.
foo = Period.where("id=1") # does AR::Relation thing
foo.select( :start ) # does AR::Relation thing
p foo.to_a # Does SQL cmd thing cuz u forced AR::Relation thing to SQL
You should only see your start column reported.
An ActiveRecord::Relation doesn't evaluate until forced to... like you want it to print values.

Related

uninitialized constant ActiveMerchant::Billing::Integrations::Helper (NameError) in Rails 5

I am try to integrate allpay payment.
gem 'rails', '>= 5.0.0.rc1', '< 5.1'
gem 'activemerchant', :require => 'active_merchant'
gem 'active_merchant_allpay'
But i am getting:
uninitialized constant ActiveMerchant::Billing::Integrations::Helper (NameError).
You will have to add offsite_payments as a dependency,and update any mentions of ActiveSupport::Billing::Integration to OffsitePayments::Integrations
https://github.com/activemerchant/active_merchant/issues/1357

Guard starts then exits?

I want to use guard to run my bacon tests, my Gemfile looks like:
source 'https://rubygems.org'
gem 'sinatra'
gem 'sidekiq'
gem 'slim'
gem 'puma'
gem 'nokogiri'
gem 'httparty'
group :test, :development do
gem 'guard'
gem 'bacon'
gem 'guard-bacon'
gem 'libnotify'
gem 'rb-inotify'
end
My Guardfile looks like
# parameters:
# output => the formatted to use
# backtrace => number of lines, nil = everything
guard 'bacon', :output => "BetterOutput", :backtrace => 4 do
watch(%r{^lib/(.+)\.rb$}) { |m| "specs/lib/#{m[1]}_spec.rb" }
watch(%r{specs/.+\.rb$})
end
When I run guard the following happens
$ guard
Bacon: Using output BetterOutput.
Bacon: Limiting backtrace to 4 lines.
09:02:05 - INFO - Guard uses Libnotify to send notifications.
09:02:05 - INFO - Guard uses TerminalTitle to send notifications.
09:02:05 - INFO - Guard is now watching at '/home/martin/code/jse-api'
Guard::Bacon started.
[1] guard(main)> %
$
It seems to load everything, get to the guard prompt and exit.
I have no idea why?
The issue seems to the version of guard required by guard-bacon 1.1.0
If you force it to the latest version of guard
gem 'guard', '>= 1.8.0'
It falls back to a older version of guard-bacon 1.0.5 and everything works.

No entry in delayed jobs table

From active admin after create of any record.
In model i have called callback method: after_save :check_delayed_job
def check_delayed_job
run_at_time = Time.now.utc + 50
Delayed::Job.enqueue(AdminNewsletterRequest.new('example#gmail.com', 'sample newsletter content'), :priority => 3 , :run_at => run_at_time)
end
But it is not making any entry in delayed job table and directly executing perform method
In lib i have created one file called admin_newsletter_request.rb
class AdminNewsletterRequest < Struct.new(:email, :subject)
def perform
UserMailer.sample_letter(email, subject).deliver
puts " weekly mail delivered succussfully! "
end
end
I am not getting how can i make entry in delayed jobs table. In log also i am not getting any error.
I want to make entry in delayed job to run the task written in perform method at run_at time.
Is their any alternate way from admin we cam make entry in delayed job to run the task at specific time.
sample application gem list
source 'https://rubygems.org'
gem 'rails', '~> 3.2.0'
gem 'pg'
gem 'daemons'
gem 'delayed_job_active_record'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
gem 'sqlite3'
# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'sass-rails', '~> 3.2.3'
gem 'coffee-rails', '~> 3.2.1'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
gem 'therubyracer', :platforms => :ruby
gem 'uglifier', '>= 1.0.3'
end
gem 'jquery-rails'
# To use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.0.0'
# To use Jbuilder templates for JSON
# gem 'jbuilder'
# Use unicorn as the app server
# gem 'unicorn'
# Deploy with Capistrano
# gem 'capistrano'
# To use debugger
# gem 'debugger'
For sample application I am able to make entry in delayed job:
Below í is the console output
1.9.2-p290 :002 > Delayed::Job.enqueue(AdminNewsletterRequest.new('example#gmail.com', 'sample newsletter content'), :priority => 3 , :run_at => run_at_time)
(0.4ms) BEGIN
SQL (103.4ms) INSERT INTO "delayed_jobs" ("attempts", "created_at", "failed_at", "handler", "last_error", "locked_at", "locked_by", "priority", "queue", "run_at", "updated_at") VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11) RETURNING "id" [["attempts", 0], ["created_at", Thu, 13 Dec 2012 07:27:49 UTC +00:00], ["failed_at", nil], ["handler", "--- !ruby/struct:AdminNewsletterRequest \nemail: example#gmail.com\nsubject: sample newsletter content\n"], ["last_error", nil], ["locked_at", nil], ["locked_by", nil], ["priority", 3], ["queue", nil], ["run_at", Thu, 13 Dec 2012 07:28:22 UTC +00:00], ["updated_at", Thu, 13 Dec 2012 07:27:49 UTC +00:00]]
(13.6ms) COMMIT
=> #<Delayed::Backend::ActiveRecord::Job id: 9, priority: 3, attempts: 0, handler: "--- !ruby/struct:AdminNewsletterRequest \nemail: san...", last_error: nil, run_at: "2012-12-13 07:28:22", locked_at: nil, failed_at: nil, locked_by: nil, queue: nil, created_at: "2012-12-13 07:27:49", updated_at: "2012-12-13 07:27:49">
1.9.2-p290 :003 >
But the application in which I am working on from the console I am getting something different output. Below is the sample output.
Delayed::Job.enqueue(AdminNewsletterRequest.new('example#gmail.com', 'sample newsletter content'), :priority => 3 , :run_at => run_at_time)
weekly mail delivered succussfully!
=> #<Delayed::Backend::ActiveRecord::Job id: nil, priority: 0, attempts: 0, handler: "--- !ruby/struct:AdminNewsletterRequest \nemail: san...", last_error: nil, run_at: nil, locked_at: nil, failed_at: nil, locked_by: nil, queue: nil, created_at: nil, updated_at: nil>
Working application gem list
source 'http://rubygems.org'
gem 'rails', '~> 3.2.0'
gem 'pg'
# Gem used by scap:
# To minimize merge conflicts, keep this list sorted alphabetically
gem 'activeadmin', '>= 0.5'
gem 'airbrake'
gem 'braintree'
gem 'compass', '~> 0.12.alpha.0'
gem 'context-io', git: 'https://github.com/henrikhodne/context-io.git'
gem 'covenant'
gem 'delayed_job_active_record'
gem 'devise', '~> 2.0.0'
gem 'dragonfly'
gem 'fog'
gem 'foreigner'
gem 'formtastic', '~> 2.2.1'
gem 'friendly_id'
gem 'geocoder'
gem 'gmaps4rails'
gem 'haml', '~> 3.1'
gem 'has_scope'
gem 'hashie'
gem 'httparty'
gem 'i18n-js'
gem 'jquery-rails'
gem 'js-routes'
gem 'kaminari'
gem 'meta_search', '>= 1.1.0.pre'
gem 'newrelic_rpm'
gem 'omniauth'
gem 'omniauth-google-oauth2'
gem 'pry-rails'
gem 'rdiscount'
gem 'seed-fu'
gem 'simple-navigation'
gem 'thin'
gem 'uuidtools'
gem 'valid_email', require: 'valid_email/email_validator'
gem 'valium'
gem 'yipit_n4l', require: 'yipit', git: 'git://github.com/Nest4LessDev/yipit.git'
#gem 'bootstrap-colorpicker-rails', :require => 'bootstrap-colorpicker-rails',
#:git => 'git://github.com/alessani/bootstrap-colorpicker-rails.git'
gem 'jquery-minicolors-rails'
gem 'therubyracer'
gem 'jquery-timepicker-rails'
# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'sass-rails'
gem 'coffee-rails'
gem 'uglifier', '>= 1.0.3'
gem 'haml_coffee_assets'
end
group :test do
gem 'cucumber-rails', require: false
gem 'database_cleaner'
gem 'email_spec'
gem 'factory_girl_rails'
gem 'capybara'
gem 'rr'
gem 'shoulda-matchers'
gem 'valid_attribute'
gem "shoulda-matchers"
gem 'fake_braintree', require: false
end
group :development, :test do
gem 'launchy'
gem 'rspec-rails'
gem 'awesome_print', :require => 'ap' # pretty print objects in console via `ap my_object`
end
gem 'pry'
Is it problem with the gem dependences, I am not able to track it out.

Environment conflicts with WickedPDF and Heroku

I am using WickedPDF, and I have basically two gems that include the binaries:
gem "wkhtmltopdf-heroku", "1.0.0"
gem "wkhtmltopdf-binary", "0.9.5.3"
The first one is supposed to be just for production, and the second one for development. The deployment to Heroku doesn't work if I have my Gemfile like:
group :development do
gem "wkhtmltopdf-binary", "0.9.5.3"
end
group :production do
gem "wkhtmltopdf-heroku", "1.0.0"
end
And it doesn't work either if I have it like:
group :production do
gem "wkhtmltopdf-heroku", "1.0.0"
end
It just works if I have it without groups. Just like:
gem "wkhtmltopdf-heroku", "1.0.0"
The error that I get is:
RuntimeError: Location of wkhtmltopdf unknown
Why would this happen? Why Heroku is not using the production group?
WickedPdf tries to figure out where the wkhtmltopdf binary lives, but can have a hard time on some systems (particularly shared servers).
You probably have to set it manually in an initializer something like this:
bin_location = case Rails.env
when 'production' then "/wherever/your/binary/is/bin/wkhtmltopdf"
when 'development' then "/local/path/to/wkthmltopdf"
else `which wkhtmltopdf`
end
WickedPdf.config = { :exe_path => bin_location }

Undefined webrat methods in cucumber step_definitions

When i run my features i get this error:
undefined method `visit' for #<Cucumber::Rails::World:0x81b17ac0> (NoMethodError)
This is the relevant part of my Gemfile.
group :development, :test do
gem "rspec-rails", ">= 2.0.0.beta.19"
gem "cucumber"
gem "cucumber-rails", ">= 0.3.2"
gem 'webrat', ">= 0.7.2.beta.1"
end
The relating step_definition (though i don't think it's important)
When /^I create a movie Caddyshack in the Comendy genre$/ do
visit movies_path
click_link "Add Movie"
fill_in "Title", :with => "Caddyshack"
check "Comedy"
click_button "Save"
end
In the env.rb i have the following Webrat configuration:
# […]
require 'webrat'
require 'webrat/core/matchers'
Webrat.configure do |config|
config.mode = :rails
config.open_error_files = false # Set to true if you want error pages to pop up in the browser
end
# […]
Anything i am missing here?
I had to set config.mode to :rack instead of :rails:
# […]
require 'webrat'
require 'webrat/core/matchers'
Webrat.configure do |config|
config.mode = :rack
config.open_error_files = false # Set to true if you want error pages to pop up in the browser
end
# […]
now works as expected.
Paul Nelligan try adding this to env.rb to fix the error : "no such file to load -- action_controller/integration"
World(Webrat::Methods)
World(Webrat::Matchers)
I also encountered this error on two separate occasions: the first instance the adjustment to confg.mode solved the problem; the second time, however, after a lot of frustration I found a link that suggested a buggy version of bundler could be the culprit. Updating it solved the problem.