I´m new to Ruby and the gem kamelopard.
I have installed RUBY VERSION: 2.0.0 (2014-05-08 patchlevel 481) [i386-mingw32], and kamelopard 0.0.15
When trying to run this program
require 'rubygems'
require 'kamelopard'
include Kamelopard
include Kamelopard::Functions
make_function_path(10,
:latitude => Line.interpolate(38.8, 40.3),
:longitude => Cubic.interpolate(-112.4, -111.9, -0.5, -113, 0.5, -110),
:altitude => Line.interpolate(10000, 2000),
:heading => Line.interpolate(0, 90),
:tilt => Line.interpolate(40.0, 90),
:altitudeMode => :absolute,
#:extrude => 1,
#:roll => 0,
:show_placemarks => 1,
:duration => Quadratic.interpolate(2.0, 4.0, 0.0, 1.0),
) do |a, v|
if v.has_key? :callback_value then
v[:callback_value] += 1
else
v[:pause] = 0.01
v[:callback_value] = 1
end
v
end
name_document 'Functions test'
name_folder 'Placemarks'
name_tour 'Function test'
write_kml_to 'doc.kml'
I get the following error message, I would appreciate your help to understand why.
C:/Ruby200/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- bundler/setup (LoadError)
from C:/Ruby200/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from C:/Ruby200/lib/ruby/gems/2.0.0/gems/kamelopard-0.0.15/lib/kamelopard/classes.rb:53:in `<module:Kamelopard>'
from C:/Ruby200/lib/ruby/gems/2.0.0/gems/kamelopard-0.0.15/lib/kamelopard/classes.rb:52:in `<top (required)>'
from C:/Ruby200/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from C:/Ruby200/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from C:/Ruby200/lib/ruby/gems/2.0.0/gems/kamelopard-0.0.15/lib/kamelopard.rb:1:in `<top (required)>'
from C:/Ruby200/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:135:in `require'
from C:/Ruby200/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:135:in `rescue in require'
from C:/Ruby200/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:144:in `require'
from C:/Users/Dasaecor/Documents/Kamelopard/Prueba.rb:2:in `<main>'
Many thanks in advance for your help. David
After installing the "bundler" and "libxml-ruby (2.7.0 x86-mingw32)" gems, i still get the following error message:
C:/Ruby200/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- libxml_ruby (LoadError)
from C:/Ruby200/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from C:/Ruby200/lib/ruby/gems/2.0.0/gems/libxml-ruby-2.7.0-x86-mingw32/lib/libxml.rb:8:in `rescue in <top (required)>'
from C:/Ruby200/lib/ruby/gems/2.0.0/gems/libxml-ruby-2.7.0-x86-mingw32/lib/libxml.rb:4:in `<top (required)>'
from C:/Ruby200/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from C:/Ruby200/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from C:/Ruby200/lib/ruby/gems/2.0.0/gems/libxml-ruby-2.7.0-x86-mingw32/lib/xml.rb:13:in `<top (required)>'
from C:/Ruby200/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:135:in `require'
from C:/Ruby200/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:135:in `rescue in require'
from C:/Ruby200/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:144:in `require'
from C:/Ruby200/lib/ruby/gems/2.0.0/gems/kamelopard-0.0.15/lib/kamelopard/classes.rb:55:in `<module:Kamelopard>'
from C:/Ruby200/lib/ruby/gems/2.0.0/gems/kamelopard-0.0.15/lib/kamelopard/classes.rb:52:in `<top (required)>'
from C:/Ruby200/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from C:/Ruby200/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from C:/Ruby200/lib/ruby/gems/2.0.0/gems/kamelopard-0.0.15/lib/kamelopard.rb:1:in `<top (required)>'
from C:/Ruby200/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:135:in `require'
from C:/Ruby200/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:135:in `rescue in require'
from C:/Ruby200/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:144:in `require'
from C:/Users/Dasaecor/Documents/Kamelopard/Prueba.rb:2:in `<main>'
One of the kamelopard (0.15) files, classes.rb, begins with this code:
module Kamelopard
require 'bundler/setup'
require 'singleton'
require 'xml'
require 'yaml'
require 'erb'
require 'cgi'
The cgi, erb, yaml, and singleton modules are part of the Ruby Standard Library, so your ruby installation provides those modules. However, the 'xml' and 'bundler/setup' modules are not part of the ruby standard library. You can install the Bundler gem to get rid of your error--but then you will get a similar error for 'xml'. There has been no 'xml' module in the Ruby Standard Library) since at least version 1.8.7, and there is no 3rd party gem named xml:
$ gem search xml
*** REMOTE GEMS ***
actionpack-xml_parser (1.0.1)
active_xml (0.0.3)
age_de_xml (0.1.0)
allhomes_xml (0.1.2)
android-xml (1.2.2)
anychart_xml_builder (0.0.12)
array-xml_serialization (0.1.0)
asir_xml (1.1.12)
axml (0.0.7)
baixarxml (0.0.4)
beardley-xml (1.1.1)
beerxml (0.3.0)
bio-blastxmlparser (1.1.1)
bio-lazyblastxml (0.4.0)
bio-nexml (1.1.0)
bio-phyloxml (0.9.0)
bio-raxml (0.1.0)
capcode-render-xml (0.1.0)
cocoa-xml (0.4.5)
codemodels-xml (0.1.2 java)
correios-sro-xml (0.2.1)
coupa-libxml-ruby (1.1.4)
cxml (0.1.0)
debugger-xml (0.3.3)
dfxml (0.2.2)
diff2xml (0.0.2)
dir-to-xml (0.3.3)
dm-xml-adapter (0.587)
dtefacil_xml_builder (0.0.11)
eim_xml (0.0.4)
eimxml (0.0.3.1)
elibri_xml_versions (0.1.11)
em-xmlrpc-client (1.0.1)
endeca_xml (0.9.0)
equivalent-xml (0.4.3)
evma_xmlpushparser (0.0.1)
excelxml (0.1.2)
fabulator-xml (0.0.5)
faster_xml_simple (0.5.0)
faster_xml_simple_reader (0.0.1)
fastxml (0.1.92)
flexmls_api (0.7.5)
flexmls_gems (0.2.9)
FlightXML2RESTDriver (0.1.4)
gccxml_gem (0.9.3 ruby x86-darwin-10 x86-darwin-11 x86-linux x86_64-linux, 0.9.2 universal-darwin-10 x86-cygwin x86-darwin-9 x86-mingw32)
gravitext-xmlprod (1.7.0 java)
hash2xml (0.0.1)
hash_to_xml (1.0.1)
hashtoxml (0.0.5)
iab-ActiveRecordBDBXml (0.2.0)
irxml (0.0.0)
jasmine_junitxml_formatter (0.1.0)
java2ruby-xmldsig (0.2)
javabean_xml (0.1.2)
jexml (0.1.0 jruby)
jrexml (0.5.3)
jrubyfx-fxmlloader (0.3 java, 0.0.1)
jxmlvalidator (0.1.2)
libxml-ext (0.4.2)
libxml-feed (0.0.1)
libxml-fixed-jruby (1.0.0 jruby)
libxml-jruby (1.0.0)
libxml-jruby-fixed (1.0.0 jruby)
libxml-ruby (2.7.0 ruby x86-mingw32, 1.1.4 x86-mswin32-60)
libxml-ruby-r19mingw (1.1.4)
libxml-to-hash (0.2.1)
libxml-xmlrpc (0.1.5)
libxml4r (0.2.6)
lustr-mxml (0.1.0)
magic-xml (0.2013.04.14)
magic_xml (0.1.1)
MergeAsXML (0.0.4)
mezza-testunitxml (0.1.6.1)
middleman-xmlvalidator (0.2.1)
MINT-scxml (1.1.7)
model_xml (1.0.13)
multi_xml (0.5.5)
mysql-xml (0.1.1)
nessus-xmlrpc (0.5.0)
nokogiri-xmlsec (0.0.4)
nom-xml (0.5.1)
objectify-xml (0.2.3)
oddb2xml (1.8.5)
olap4r-xmla (0.1.0)
open_xml (0.0.2)
open_xml_package (0.0.3)
opinionated-xml (0.1.0)
oracle_enhanced_plus_xmltype (0.0.5)
osheet-xmlss (1.0.0)
oxmlk (0.4.0)
oxmlrpc (0.2)
pacer-xml (0.2.4 java)
pg-xml (0.0.2)
pretty-xml (0.1.3)
prova-vhm-raw2xml (1.0.0)
pseudoxml (0.1.0)
qbxml (0.1.5)
qbxml-dtd6 (1.0.3)
rack-xml_stylesheet (0.0.1)
rails-xmlrpc (0.3.7)
rbgccxml (1.0.4)
rdbxml (2.4.13.2)
rdf-rdfxml (1.1.0.1)
rdf-xml (0.0.3)
rexml-expansion-fix (1.0.1)
rivsc-xmlattributes (1.0.0)
ROXML (3.0.0)
roxml (3.3.1)
rraxml (0.1.2)
rspec-xml (0.0.6)
rsxml (0.4.1)
rtiss_libxml_to_hash (0.3.0)
ruby-xml-mapper (1.0.8)
ruby-xml-smart (0.2.99.3, 0.1.12.1 i486-linux)
rubyjedi-testunitxml (0.1.5.20100616141003)
rubysl-rexml (2.0.2)
rubysl-xmlrpc (2.0.0)
sads_xml (0.0.4)
salad-xml_page (0.3.4)
sandozxmlconv (1.0.0)
scxml (0.1.0)
signed_xml (1.0.1)
simple-xml (1.0.0)
sixarm_ruby_rexml (2.1.0)
sixarm_ruby_rexml_element_new_with_options (1.2.0)
sixarm_ruby_xml_load (2.1.0)
sixarm_ruby_xml_strip (2.1.0)
smile-xml (1.0.3 java jruby)
sprout-mxml-bundle (0.1.13)
test_xml (0.1.6)
testunitxml (0.1.5)
texml (0.5.0)
the-experimenters-rdf-rdfxml (0.3.4)
thinp_xml (0.0.15)
tiny_xml_builder (0.0.4)
tkxml (0.3.1)
to_xml (0.1.1)
ts-xml (1.0.3)
tuxml (0.0.1)
validates_xml (1.0.3)
vcr-xml (0.0.3)
vtd-xml (0.0.3 java)
vtd_xml (0.0.6 java)
vxml-tools (1.0.0)
wbxml (0.0.2)
wbxml-npn47 (0.0.2)
whm_xml (0.3.2)
wordpress-xmlrpc (0.0.11)
wordpress-xmlrpc-api (0.0.1)
wpxml_parser (0.0.1)
xml-focus (0.0.1)
xml-fu (0.2.0)
xml-magic (0.1.1)
xml-mapping (0.9.1)
xml-motor (0.1.6)
xml-object (0.9.93)
xml-purifier (0.1.4)
xml-registry (0.2.3)
xml-sax-machines (0.4.2)
xml-simple (1.1.3)
xml-sitemap (1.3.3)
xml-smart (0.3.9)
xml-spec (0.3.0)
xml-to-haml (0.1.7)
xml2csv (0.0.1)
xml2go (0.0.3)
xml_active (0.0.6)
xml_contacts_extractor (0.0.5)
xml_convert (0.1.0)
xml_data_builder (1.0.0)
xml_errors_parser (0.0.2)
xml_escape (0.0.2)
xml_file_renamer (0.0.8)
xml_fixtures (0.1.1)
xml_hate (0.8.3.4)
xml_mapper (0.5.8)
xml_mini (0.1.0)
xml_node_stream (1.0.2)
xml_resource (2.0.5)
xml_schema (0.2.0)
xml_schema_mapper (0.0.12)
xml_security (0.0.3)
xml_serialization (0.1.2)
xml_signature (0.1)
xml_soccer (0.0.4)
xml_spec (0.1.0)
xml_split (0.0.2)
xml_stream_parser (0.3.0)
xml_to_json (0.0.2)
xml_uglifier (0.0.2)
xmlblog-acts_as_versioned (0.6.5)
XMLCanonicalizer (1.0.1)
xmlcanonicalizer (0.1.2)
xmlcellent (0.1.0)
xmlcodec (0.3.2)
xmlconv (1.0.1)
xmlconv2 (2.0.0)
xmldsig (0.2.4)
xmldsig-fiscalizer (0.2.5)
xmldsign (0.2.0)
XmlEasy (0.0.2)
xmlelements (0.1.2)
xmlenc (0.1.3)
xmlhash (1.3.6)
xmlhasher (0.0.6)
xmlish (0.0.1)
xmlize (0.1.1)
xmlobject (0.2)
xmlparsable (1.5.4)
xmlparser (0.7.2.1)
xmlpipe2_indexer (0.0.2)
xmlpretty (0.1.0)
xmlresume2x (0.2.1)
XMLROCS (0.0.1)
xmlrpc-endpoint (0.2.1)
xmlrpc-rack (0.0.1)
xmlrpc-rack_server (0.0.1)
xmlrpc-streaming (0.1.0)
xmlrpc_controller (0.0.7)
xmlrpcs (0.1.3)
xmlscan (0.3.0)
xmlsec (0.0.6)
xmlsec-ruby (0.0.7)
xmlsec-shim (1.2.18.2)
xmlsig (0.0.3)
xmlsoccer (0.1.0)
xmlss (1.0.0)
xmlstats (1.6.1)
xmlstreamin (0.0.1)
xmlstruct (1.0.0)
xmltv (0.8.7)
xmltv2html (0.8.0)
xmlvalidate (0.1.0)
yard-xml (0.1.3)
yaxml (0.1)
yob-roxml (3.1.6)
It looks like the gem was recently updated, so I would try to get in contact with the author and ask him/her where/what the xml module is.
Okay, if you install the libxml-ruby gem, that provides an xml module, which can be required by kamelopard.
Related
I am learning Sinatra and Rom. I forked the dusty sinatra-rom project on GitHub.
I run the program with bundle exec rackup.
This issue has me stumped:
db/commands/products/create.rb throws undefined method relation for CreateProduct:Class (NoMethodError) relation :products
Here is the start of that file:
class CreateProduct < ROM::SQL::Commands::Create[:sql]
relation :products
register_as :create
...
Both the relation and the register_as commands are not recognized.
This is the Gemfile:
Gemfile
source "https://rubygems.org"
gem 'bundler'
gem 'sinatra'
gem 'rom', github: 'rom-rb/rom'
gem 'rom-sql', github: 'rom-rb/rom-sql'
gem 'virtus'
gem 'lotus-validations'
# gem 'puma'
gem 'dotenv'
gem 'multi_json'
gem 'oj'
gem 'activesupport'
gem 'bcrypt'
group :development, :test do
gem 'sqlite3'
end
group :test do
gem 'rspec'
gem 'rack-test'
gem 'database_cleaner'
end
Gemfile.lock is:
GIT
remote: https://github.com/rom-rb/rom-sql.git
revision: 596fea491ace84ae1aea12599879f84cb0ce5b64
specs:
rom-sql (4.0.0.alpha1)
dry-core (~> 1.0)
dry-types (~> 1.7)
rom (~> 6.0.0.alpha)
sequel (>= 5)
GIT
remote: https://github.com/rom-rb/rom.git
revision: 7fb82cf7ffa86805d9c5499a4ecc64d5d3c20f14
specs:
rom (6.0.0.alpha1)
concurrent-ruby (~> 1.1)
dry-core (>= 1.0.0.rc1, < 2)
dry-effects (~> 0.4)
dry-inflector (>= 1.0.0.rc1, < 2)
dry-initializer (~> 3.1)
dry-struct (~> 1.4)
dry-transformer (~> 1.0)
dry-types (~> 1.5)
zeitwerk (~> 2.6)
GEM
remote: https://rubygems.org/
specs:
activemodel (7.0.4.2)
activesupport (= 7.0.4.2)
activerecord (7.0.4.2)
activemodel (= 7.0.4.2)
activesupport (= 7.0.4.2)
activesupport (7.0.4.2)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 1.6, < 2)
minitest (>= 5.1)
tzinfo (~> 2.0)
axiom-types (0.1.1)
descendants_tracker (~> 0.0.4)
ice_nine (~> 0.11.0)
thread_safe (~> 0.3, >= 0.3.1)
bcrypt (3.1.18)
coercible (1.0.0)
descendants_tracker (~> 0.0.1)
concurrent-ruby (1.2.0)
database_cleaner (2.0.1)
database_cleaner-active_record (~> 2.0.0)
database_cleaner-active_record (2.0.1)
activerecord (>= 5.a)
database_cleaner-core (~> 2.0.0)
database_cleaner-core (2.0.1)
descendants_tracker (0.0.4)
thread_safe (~> 0.3, >= 0.3.1)
diff-lcs (1.5.0)
dotenv (2.8.1)
dry-core (1.0.0)
concurrent-ruby (~> 1.0)
zeitwerk (~> 2.6)
dry-effects (0.4.0)
concurrent-ruby (~> 1.0)
dry-core (~> 1.0)
dry-inflector (~> 1.0)
dry-initializer (~> 3.0)
zeitwerk (~> 2.6)
dry-inflector (1.0.0)
dry-initializer (3.1.1)
dry-logic (1.5.0)
concurrent-ruby (~> 1.0)
dry-core (~> 1.0, < 2)
zeitwerk (~> 2.6)
dry-struct (1.6.0)
dry-core (~> 1.0, < 2)
dry-types (>= 1.7, < 2)
ice_nine (~> 0.11)
zeitwerk (~> 2.6)
dry-transformer (1.0.1)
zeitwerk (~> 2.6)
dry-types (1.7.0)
concurrent-ruby (~> 1.0)
dry-core (~> 1.0, < 2)
dry-inflector (~> 1.0, < 2)
dry-logic (>= 1.4, < 2)
zeitwerk (~> 2.6)
i18n (1.12.0)
concurrent-ruby (~> 1.0)
ice_nine (0.11.2)
lotus-utils (0.6.1)
lotus-validations (0.4.0)
lotus-utils (~> 0.6)
minitest (5.17.0)
multi_json (1.15.0)
mustermann (3.0.0)
ruby2_keywords (~> 0.0.1)
oj (3.13.23)
rack (2.2.6.2)
rack-protection (3.0.5)
rack
rack-test (2.0.2)
rack (>= 1.3)
rspec (3.12.0)
rspec-core (~> 3.12.0)
rspec-expectations (~> 3.12.0)
rspec-mocks (~> 3.12.0)
rspec-core (3.12.0)
rspec-support (~> 3.12.0)
rspec-expectations (3.12.2)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.12.0)
rspec-mocks (3.12.3)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.12.0)
rspec-support (3.12.0)
ruby2_keywords (0.0.5)
sequel (5.64.0)
sinatra (3.0.5)
mustermann (~> 3.0)
rack (~> 2.2, >= 2.2.4)
rack-protection (= 3.0.5)
tilt (~> 2.0)
sqlite3 (1.6.0-x86_64-linux)
thread_safe (0.3.6)
tilt (2.0.11)
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
virtus (2.0.0)
axiom-types (~> 0.1)
coercible (~> 1.0)
descendants_tracker (~> 0.0, >= 0.0.3)
zeitwerk (2.6.6)
PLATFORMS
x86_64-linux
DEPENDENCIES
activesupport
bcrypt
bundler
database_cleaner
dotenv
lotus-validations
multi_json
oj
rack-test
rom!
rom-sql!
rspec
sinatra
sqlite3
virtus
BUNDLED WITH
2.4.5
Am I missing a gem?
I have a helper file in my sinatra app that has the following code:
todo_sinatra_app/helpers/sessions_helper.rb
class SessionsHelper
def self.sign_in(user)
cookies[:remember_token] = { value: user.remember_token, expires: 20.years.from_now.utc }
self.current_user = user
end
...
end
When I try to call on the sign_in method from my app.rb file, it throws an error that it doesn't know how to create cookies:
require 'sinatra'
require 'pg'
require 'sinatra/activerecord'
require 'sinatra/contrib'
require 'sinatra/cookies'
require './helpers/sessions_helper'
...
post '/sign_in' do
user = User.find_by(email: params[:email])
if user && user.authenticate(params[:password])
SessionsHelper.sign_in(user)
redirect '/'
else
...
end
Here is my gemfile.lock
GEM
remote: https://rubygems.org/
specs:
activemodel (5.2.0)
activesupport (= 5.2.0)
activerecord (5.2.0)
activemodel (= 5.2.0)
activesupport (= 5.2.0)
arel (>= 9.0)
activesupport (5.2.0)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 0.7, < 2)
minitest (~> 5.1)
tzinfo (~> 1.1)
arel (9.0.0)
backports (3.16.0)
bcrypt (3.1.13)
byebug (11.0.1)
coderay (1.1.2)
concurrent-ruby (1.1.5)
daemons (1.3.1)
diff-lcs (1.3)
eventmachine (1.2.7)
i18n (1.8.2)
concurrent-ruby (~> 1.0)
method_source (0.9.2)
minitest (5.14.0)
multi_json (1.14.1)
mustermann (1.1.1)
ruby2_keywords (~> 0.0.1)
pg (1.2.2)
pry (0.12.2)
coderay (~> 1.1.0)
method_source (~> 0.9.0)
pry-byebug (3.7.0)
byebug (~> 11.0)
pry (~> 0.10)
rack (2.1.2)
rack-protection (2.0.8.1)
rack
rack-test (1.1.0)
rack (>= 1.0, < 3)
rake (13.0.1)
rspec (3.9.0)
rspec-core (~> 3.9.0)
rspec-expectations (~> 3.9.0)
rspec-mocks (~> 3.9.0)
rspec-core (3.9.1)
rspec-support (~> 3.9.1)
rspec-expectations (3.9.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.9.0)
rspec-mocks (3.9.1)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.9.0)
rspec-support (3.9.2)
ruby2_keywords (0.0.2)
sinatra (2.0.8.1)
mustermann (~> 1.0)
rack (~> 2.0)
rack-protection (= 2.0.8.1)
tilt (~> 2.0)
sinatra-activerecord (2.0.14)
activerecord (>= 3.2)
sinatra (>= 1.0)
sinatra-contrib (2.0.8.1)
backports (>= 2.8.2)
multi_json
mustermann (~> 1.0)
rack-protection (= 2.0.8.1)
sinatra (= 2.0.8.1)
tilt (~> 2.0)
sinatra-flash (0.3.0)
sinatra (>= 1.0.0)
thin (1.7.2)
daemons (~> 1.0, >= 1.0.9)
eventmachine (~> 1.0, >= 1.0.4)
rack (>= 1, < 3)
thread_safe (0.3.6)
tilt (2.0.10)
tzinfo (1.2.6)
thread_safe (~> 0.1)
PLATFORMS
ruby
DEPENDENCIES
activerecord (= 5.2)
bcrypt
minitest (= 5.14.0)
pg
pry-byebug
rack-test
rake
rspec
sinatra
sinatra-activerecord
sinatra-contrib
sinatra-flash
thin
BUNDLED WITH
2.1.4
I've tried with putting the require 'sinatra/cookies' inside the helper file, and made sure that I have the gem 'sinatra-contrib' bundled. It works when I set a cookie directly in my app.rb file. Can anyone suggest anything else that I can check or what could be the issue?
When you require 'sinatra' certain magic things happen that brings a bunch of stuff into scope and essentially turns your app.rb into an instance of Sinatra::Application. The cookies method is only defined on instances like this – it isn’t present on other classes automatically.
What you probably want to do is turn your helper into a real Sinatra style helper by making it a module and then loading it using the helpers keyword, which will just make these instance methods:
module SessionsHelper
def sign_in(user)
cookies[:remember_token] = { value: user.remember_token, expires: 20.years.from_now.utc }
self.current_user = user
end
...
end
And in your main file:
require './helpers/sessions_helper'
helpers SessionsHelper
...
post '/sign_in' do
user = User.find_by(email: params[:email])
if user && user.authenticate(params[:password])
sign_in user
redirect '/'
else
...
end
You might like to read more about this in the README.
I have a ruby app and it makes a connection to SQL server (works fine) and Postgres (breaking). I don't know how to debug this. I tried connecting to the postgres database from the command line and it worked (without a password actually).
It throws a ActiveRecord::ConnectionNotEstablished error on the first line:
nti_shipment.line_items.each_with_index do |nti_line_item,i|
#logger.info "\n\nadd line item to shipto: "+nti_line_item.botcode+"****"
product = Web::Product.find_by_nti_product_id(nti_line_item.botcode)
#is_message = (i > 0 && (not product)) ? true : false
is_message = (nti_line_item.productid == 0) ? true : false
if !(is_message)
web_line_item = web_shipment.add_line_item(nti_line_item)
last_item = web_line_item
nti_line_item.itemid = web_line_item.id
nti_line_item.save!
elsif i > 0
last_item.line_item_messages << Web::LineItemMessage.add(last_item,nti_line_item)
end
end
And this is the database.yml file I'm using:
production:
adapter: postgresql
database: mysite_production
username: myuser
password: "password"
options: "-o sslmode=require"
host: localhost
This is the full trace:
I, [2013-10-03T10:24:45.034384 #16480] INFO -- : ActiveRecord::ConnectionNotEstablished
I, [2013-10-03T10:24:45.105416 #16480] INFO -- : /usr/local/rvm/gems/ruby-1.9.3-p448/gems/activerecord-3.2.14/lib/active_record/connection_adapters/abstract/connection_pool.rb:410:in `retrieve_connection'
/usr/local/rvm/gems/ruby-1.9.3-p448/gems/activerecord-3.2.14/lib/active_record/connection_adapters/abstract/connection_specification.rb:171:in `retrieve_connection'
/usr/local/rvm/gems/ruby-1.9.3-p448/gems/activerecord-3.2.14/lib/active_record/connection_adapters/abstract/connection_specification.rb:145:in `connection'
/usr/local/rvm/gems/ruby-1.9.3-p448/gems/activerecord-sqlserver-adapter-3.2.12/lib/arel/visitors/sqlserver.rb:81:in `engine_activerecord_sqlserver_adapter?'
/usr/local/rvm/gems/ruby-1.9.3-p448/gems/activerecord-sqlserver-adapter-3.2.12/lib/arel/visitors/sqlserver.rb:33:in `order'
/usr/local/rvm/gems/ruby-1.9.3-p448/gems/activerecord-3.2.14/lib/active_record/relation/query_methods.rb:279:in `build_arel'
/usr/local/rvm/gems/ruby-1.9.3-p448/gems/activerecord-3.2.14/lib/active_record/relation/query_methods.rb:260:in `arel'
/usr/local/rvm/gems/ruby-1.9.3-p448/gems/activerecord-3.2.14/lib/active_record/relation.rb:171:in `exec_queries'
/usr/local/rvm/gems/ruby-1.9.3-p448/gems/activerecord-3.2.14/lib/active_record/relation.rb:160:in `block in to_a'
/usr/local/rvm/gems/ruby-1.9.3-p448/gems/activerecord-3.2.14/lib/active_record/explain.rb:41:in `logging_query_plan'
/usr/local/rvm/gems/ruby-1.9.3-p448/gems/activerecord-3.2.14/lib/active_record/relation.rb:159:in `to_a'
/usr/local/rvm/gems/ruby-1.9.3-p448/gems/activerecord-3.2.14/lib/active_record/relation/finder_methods.rb:159:in `all'
/usr/local/rvm/gems/ruby-1.9.3-p448/gems/activerecord-3.2.14/lib/active_record/associations/collection_association.rb:382:in `find_target'
/usr/local/rvm/gems/ruby-1.9.3-p448/gems/activerecord-3.2.14/lib/active_record/associations/collection_association.rb:335:in `load_target'
/usr/local/rvm/gems/ruby-1.9.3-p448/gems/activerecord-3.2.14/lib/active_record/associations/collection_proxy.rb:44:in `load_target'
/usr/local/rvm/gems/ruby-1.9.3-p448/gems/activerecord-3.2.14/lib/active_record/associations/collection_proxy.rb:87:in `method_missing'
/usr/local/sl-exchange/app/controllers/order_controller.rb:219:in `block (4 levels) in create_web_orders'
/usr/local/rvm/gems/ruby-1.9.3-p448/gems/activerecord-3.2.14/lib/active_record/associations/collection_proxy.rb:89:in `each'
/usr/local/rvm/gems/ruby-1.9.3-p448/gems/activerecord-3.2.14/lib/active_record/associations/collection_proxy.rb:89:in `method_missing'
/usr/local/sl-exchange/app/controllers/order_controller.rb:194:in `block (3 levels) in create_web_orders'
/usr/local/rvm/gems/ruby-1.9.3-p448/gems/activerecord-sqlserver-adapter-3.2.12/lib/active_record/connection_adapters/sqlserver/database_statements.rb:52:in `block in transaction'
/usr/local/rvm/gems/ruby-1.9.3-p448/gems/activerecord-sqlserver-adapter-3.2.12/lib/active_record/connection_adapters/sqlserver/core_ext/database_statements.rb:37:in `transaction_with_retry_deadlock_victim'
/usr/local/rvm/gems/ruby-1.9.3-p448/gems/activerecord-sqlserver-adapter-3.2.12/lib/active_record/connection_adapters/sqlserver/database_statements.rb:52:in `transaction'
/usr/local/rvm/gems/ruby-1.9.3-p448/gems/activerecord-3.2.14/lib/active_record/transactions.rb:208:in `transaction'
/usr/local/sl-exchange/app/controllers/order_controller.rb:167:in `block (2 levels) in create_web_orders'
/usr/local/rvm/gems/ruby-1.9.3-p448/gems/activerecord-3.2.14/lib/active_record/connection_adapters/abstract/database_statements.rb:192:in `transaction'
/usr/local/rvm/gems/ruby-1.9.3-p448/gems/activerecord-3.2.14/lib/active_record/transactions.rb:208:in `transaction'
/usr/local/sl-exchange/app/controllers/order_controller.rb:166:in `block in create_web_orders'
/usr/local/sl-exchange/app/controllers/order_controller.rb:164:in `each'
/usr/local/sl-exchange/app/controllers/order_controller.rb:164:in `create_web_orders'
/usr/local/sl-exchange/app/controllers/order_controller.rb:28:in `start'
/usr/local/sl-exchange/lib/exchange.rb:115:in `initialize'
/usr/local/sl-exchange/lib/exchange.rb:194:in `new'
/usr/local/sl-exchange/lib/exchange.rb:194:in `<top (required)>'
/usr/local/rvm/gems/ruby-1.9.3-p448/gems/daemons-1.1.9/lib/daemons/application.rb:203:in `load'
/usr/local/rvm/gems/ruby-1.9.3-p448/gems/daemons-1.1.9/lib/daemons/application.rb:203:in `start_load'
/usr/local/rvm/gems/ruby-1.9.3-p448/gems/daemons-1.1.9/lib/daemons/application.rb:298:in `start'
/usr/local/rvm/gems/ruby-1.9.3-p448/gems/daemons-1.1.9/lib/daemons/controller.rb:70:in `run'
/usr/local/rvm/gems/ruby-1.9.3-p448/gems/daemons-1.1.9/lib/daemons.rb:147:in `block in run'
/usr/local/rvm/gems/ruby-1.9.3-p448/gems/daemons-1.1.9/lib/daemons/cmdline.rb:109:in `call'
/usr/local/rvm/gems/ruby-1.9.3-p448/gems/daemons-1.1.9/lib/daemons/cmdline.rb:109:in `catch_exceptions'
/usr/local/rvm/gems/ruby-1.9.3-p448/gems/daemons-1.1.9/lib/daemons.rb:146:in `run'
Here are my gems:
** LOCAL GEMS ***
activemodel (3.2.14)
activerecord (3.2.14)
activerecord-postgresql-adapter (0.0.1)
activerecord-sqlserver-adapter (3.2.12)
activesupport (3.2.14)
arel (3.0.2)
bigdecimal (1.1.0)
builder (3.0.4)
bundler (1.3.5)
bundler-unload (1.0.1)
daemons (1.1.9)
i18n (0.6.5)
io-console (0.3)
json (1.5.5)
mailfactory (1.4.0)
mime-types (1.24)
mini_portile (0.5.1)
minitest (2.5.1)
multi_json (1.7.9)
nokogiri (1.6.0)
pg (0.15.1)
rake (10.1.0, 0.9.2.2)
rchardet (1.3.1)
rdoc (3.9.5)
RedCloth (4.2.9)
rubygems-bundler (1.2.2)
rvm (1.11.3.8)
sanitize (2.0.6)
tiny_tds (0.6.1)
tzinfo (0.3.37)
Let me know if you need more info.
===== SQLSERVER CONFIG =====
production:
adapter: sqlserver
host: cluster.mysite.com
database: mydb
#dsn: preview
username: myuser
password: mypwd
port: 1433
when I try telnet cluster.mysite.com 1433 it works... so I don't know what's going on.
Your configuration in database.yml says postgresql, but, your error trace has activerecord-sqlserver-adapter-3.2.12 in it. So, looks like, still you are trying to connect to sqlserver.So, it is not postgres breaking, it is sqlserver breaking.
I need to get the README content of my Github repo and I went for 'Get the README' API V3, but it is encoded base64:
{
"name": "README.rdoc",
"path": "README.rdoc",
"sha": "d21b593aedfa49030478ead89c4ac991268c75c0",
"size": 4939,
"url": "https://api.github.com/repos/lgs/paymill-on-rails/contents/README.rdoc?ref=master",
"html_url": "https://github.com/lgs/paymill-on-rails/blob/master/README.rdoc",
"git_url": "https://api.github.com/repos/lgs/paymill-on-rails/git/blobs/d21b593aedfa49030478ead89c4ac991268c75c0",
"type": "file",
"content": "PT0gUGF5bWlsbCBvbiBSYWlscyA0LjAuMCAKClBheW1pbGwgc3Vic2NyaXB0\naW9ucyBvbiBSYWlscyA0LjAuMCBhbmQgcnVieS0yLjAuMC1wMjQ3LCB7ZGVw\nbG95ZWQgb24gSGVyb2t1fVtodHRwczovL3BheW1pbGwtb24tcmFpbHMuaGVy\nb2t1YXBwLmNvbV0uIFRoaXMgaXMgYmFzZWQgb24ge01hcmMgQi4nc31baHR0
...
...,
"encoding": "base64",
"_links": {
"self": "https://api.github.com/repos/lgs/paymill-on-rails/contents/README.rdoc?ref=master",
"git": "https://api.github.com/repos/lgs/paymill-on-rails/git/blobs/d21b593aedfa49030478ead89c4ac991268c75c0",
"html": "https://github.com/lgs/paymill-on-rails/blob/master/README.rdoc"
}
}
What is the way to get/convert the "content": "PT0gUGF5bWlsbCBv ..." in clear text (not base64 encoded) ?
UPDATE (just for tracking purposes):
The solution propesed by Linuxios, is also well implemented within the nice Octokit API wrapper for Ruby as following:
Octokit.contents 'lgs/paymill-on-rails', :path => 'README.rdoc', :accept => 'application/vnd.github.html'
to get the entire html and
Octokit.contents 'lgs/paymill-on-rails', :path => 'README.rdoc', :accept => 'application/vnd.github.V3.raw'
if you want the clean, raw content only :
2.0.0p247 :001 > require 'octokit'
=> true
2.0.0p247 :002 > Octokit.contents 'lgs/paymill-on-rails', :path => 'README.rdoc', :accept => 'application/vnd.github.V3.raw'
=> "== Paymill on Rails 4.0.0 \n\nPaymill subscriptions on Rails 4.0.0 and ruby-2.0.0-p247, {deployed on Heroku}[https://paymill-on-rails.herokuapp.com]. This is based on {Marc B.'s}[https://github.com/apalancat] {work}[https://github.com/apalancat/paymill-rails].\n\n== Usage\n\nRegister for a test account at {paymill.com}[https://paymill.com/] and create the subscription plans, also called Offers.\n\nSetup the app:\n\n bundle\n rake db:migrate\n \n \nReplace the test keys in \n\n config/initializers/paymill.rb \n\nfor your own paymill API keys.\n\nTo get the plans and their IDs from paymill into the app run:\n\n rake paymill:import_plans\n\nThat's it! Run \n\n rails server\n\nand it should work.\n\n== Deploy on Heroku\n\nFrom rails app's root directory path run \n\n heroku config:add BUNDLE_WITHOUT=\"development:test\"\n heroku rake db:migrate\n heroku rake paymill:import_plans\n\n== Current Bundle\n\nGEM\n remote: https://rubygems.org/\n specs:\n actionmailer (4.0.0)\n actionpack (= 4.0.0)\n mail (~> 2.5.3)\n actionpack (4.0.0)\n activesupport (= 4.0.0)\n builder (~> 3.1.0)\n erubis (~> 2.7.0)\n rack (~> 1.5.2)\n rack-test (~> 0.6.2)\n activemodel (4.0.0)\n activesupport (= 4.0.0)\n builder (~> 3.1.0)\n activerecord (4.0.0)\n activemodel (= 4.0.0)\n activerecord-deprecated_finders (~> 1.0.2)\n activesupport (= 4.0.0)\n arel (~> 4.0.0)\n activerecord-deprecated_finders (1.0.3)\n activesupport (4.0.0)\n i18n (~> 0.6, >= 0.6.4)\n minitest (~> 4.2)\n multi_json (~> 1.3)\n thread_safe (~> 0.1)\n tzinfo (~> 0.3.37)\n arel (4.0.0)\n atomic (1.1.12)\n builder (3.1.4)\n coffee-rails (4.0.0)\n coffee-script (>= 2.2.0)\n railties (>= 4.0.0.beta, < 5.0)\n coffee-script (2.2.0)\n coffee-script-source\n execjs\n coffee-script-source (1.6.3)\n erubis (2.7.0)\n execjs (1.4.0)\n multi_json (~> 1.0)\n hike (1.2.3)\n i18n (0.6.4)\n jbuilder (1.5.0)\n activesupport (>= 3.0.0)\n multi_json (>= 1.2.0)\n jquery-rails (3.0.4)\n railties (>= 3.0, < 5.0)\n thor (>= 0.14, < 2.0)\n json (1.8.0)\n mail (2.5.4)\n mime-types (~> 1.16)\n treetop (~> 1.4.8)\n mime-types (1.23)\n minitest (4.7.5)\n multi_json (1.7.8)\n paymill (0.3.0)\n json\n polyglot (0.3.3)\n rack (1.5.2)\n rack-test (0.6.2)\n rack (>= 1.0)\n rails (4.0.0)\n actionmailer (= 4.0.0)\n actionpack (= 4.0.0)\n activerecord (= 4.0.0)\n activesupport (= 4.0.0)\n bundler (>= 1.3.0, < 2.0)\n railties (= 4.0.0)\n sprockets-rails (~> 2.0.0)\n railties (4.0.0)\n actionpack (= 4.0.0)\n activesupport (= 4.0.0)\n rake (>= 0.8.7)\n thor (>= 0.18.1, < 2.0)\n rake (10.1.0)\n rdoc (3.12.2)\n json (~> 1.4)\n sass (3.2.10)\n sass-rails (4.0.0)\n railties (>= 4.0.0.beta, < 5.0)\n sass (>= 3.1.10)\n sprockets-rails (~> 2.0.0)\n sdoc (0.3.20)\n json (>= 1.1.3)\n rdoc (~> 3.10)\n sprockets (2.10.0)\n hike (~> 1.2)\n multi_json (~> 1.0)\n rack (~> 1.0)\n tilt (~> 1.1, != 1.3.0)\n sprockets-rails (2.0.0)\n actionpack (>= 3.0)\n activesupport (>= 3.0)\n sprockets (~> 2.8)\n sqlite3 (1.3.7)\n thor (0.18.1)\n thread_safe (0.1.2)\n atomic\n tilt (1.4.1)\n treetop (1.4.14)\n polyglot\n polyglot (>= 0.3.1)\n turbolinks (1.3.0)\n coffee-rails\n twitter-bootstrap-rails (2.2.7)\n actionpack (>= 3.1)\n execjs\n rails (>= 3.1)\n railties (>= 3.1)\n tzinfo (0.3.37)\n uglifier (2.1.2)\n execjs (>= 0.3.0)\n multi_json (~> 1.0, >= 1.0.2)\n\nPLATFORMS\n ruby\n\nDEPENDENCIES\n coffee-rails (~> 4.0.0)\n jbuilder (~> 1.2)\n jquery-rails\n paymill\n rails (= 4.0.0)\n sass-rails (~> 4.0.0)\n sdoc\n sqlite3\n turbolinks\n twitter-bootstrap-rails\n uglifier (>= 1.3.0)\n\n== Copyright\n\n(The MIT License)\n\nCopyright (c) 2013 Luca G. Soave\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the 'Software'), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n"
2.0.0p247 :009 >
Two options. One is just to decode it:
require 'base64'
plaintext = Base64.decode64(data['content'])
Or, you can use the raw content request on their API. Add this to your headers:
Accept: application/vnd.github.VERSION.raw
Replacing VERSION with your API version.
I am using ruby 1.9.3p429 (2013-05-15 revision 40747) [x86_64-linux] along with these gems. I have a simple DBI script that displays the DisplayNames, however the output from the script does not match the output in the Database. The output from the script fetches the last record and displays it 10 times.
My DSN is pointing to a MSSQL database.
#/usr/bin/env ruby
require 'rubygems'
require 'dbi'
oConn = DBI.connect('DBI:ODBC:DSN','username','password')
query=oConn.prepare("select top 10 DisplayName from table")
query.execute
#rows=query.fetch_all
puts #rows.size
#rows.each do |r|
puts r["DisplayName"].to_s
end
puts "done"
query.finish
oConn.disconnect
The installed gems:
*** LOCAL GEMS ***
actionmailer (3.2.13)
actionpack (3.2.13, 3.2.3)
activemodel (3.2.13, 3.2.3)
activerecord (3.2.13, 3.2.3)
activerecord-informix-adapter (1.1.1)
activerecord-odbc-adapter (2.0)
activerecord-sqlserver-adapter (3.2.10)
activeresource (3.2.13, 3.2.3)
activesupport (3.2.13, 3.2.3)
arel (3.0.2)
bigdecimal (1.1.0)
builder (3.0.4, 3.0.0)
bundler (1.3.5)
coffee-rails (3.2.2)
coffee-script (2.2.0)
coffee-script-source (1.3.3)
commonjs (0.2.6)
daemon_controller (1.1.4)
dbd-odbc (0.2.5)
dbi (0.4.5)
deprecated (2.0.1)
erubis (2.7.0)
execjs (1.4.0)
haml (3.1.6)
hike (1.2.2, 1.2.1)
i18n (0.6.1, 0.6.0)
io-console (0.3)
journey (1.0.4)
jquery-rails (2.0.2)
json (1.7.3, 1.5.5)
less (2.2.2)
less-rails (2.2.6)
libv8 (3.3.10.4 x86_64-linux)
mail (2.5.4)
mime-types (1.23)
minitest (2.5.1)
multi_json (1.7.3, 1.3.6)
passenger (4.0.4, 4.0.0.rc6)
polyglot (0.3.3)
rack (1.4.5, 1.4.1)
rack-cache (1.2)
rack-ssl (1.3.3, 1.3.2)
rack-test (0.6.2, 0.6.1)
rails (3.2.13)
railties (3.2.13, 3.2.3)
rake (10.0.4, 0.9.2.2)
rdoc (3.12, 3.9.5)
ruby-informix (0.8.0)
ruby-odbc (0.99994)
rubygems-bundler (1.1.1)
rvm (1.11.3.7)
sass (3.1.20)
sass-rails (3.2.5)
simple_form (2.0.4)
sprockets (2.2.2, 2.1.3)
sqlite3 (1.3.6)
therubyracer (0.10.1)
thor (0.18.1, 0.14.6)
tilt (1.4.1, 1.3.3)
treetop (1.4.12)
twitter-bootstrap-rails (2.2.6, 2.2.1)
tzinfo (0.3.37, 0.3.33)
uglifier (1.2.6)
will_paginate (3.0.4)
def get_record
begin
record = CONN.prepare( " SELECT * FROM questions " )
record.execute()
record.map { |row| printf "ID : %d, description : %s, marks : %d, category : %s \n", row[0], row[1], row[2] , row[3] }
rescue DBI::DatabaseError => e
puts "Error code : #{e.err}"
puts "Error message : #{e.errstr}"
end
end
CONN is a constant that is holding the connection
like CONN = Connection.new.create_connection
i did DBI connection. that is require DBI gem instollation along with driver vender # specific i am using DBD-mysql so its working fine.