Running API/gem on heroku gives Load error - ruby-on-rails

I use the payment provider Mollie in my Ruby on Rails app. It works locally but not on heroku. When I call the API, it gives the error: 500: Load error: cannot load such file -- Mollie/Api/Client. Does someone know how to load the API on heroku? Update: I think that it has something to do with the location where heroku saves the gems. And that it can't find the location of the gem (??)
I installed the gem locally by running
$ gem install mollie-api-ruby
I also added the gem to my gemfile (but don't know if this is necessary).
gem 'mollie-api-ruby'
I am not experienced in Ruby on Rails and Heroku, but I hope that someone has a tip to get this working. Thanks!
I request this API in a controller by:
def create
#thrill = Thrill.find(params[:thrill_id])
if #thrill.reservations.length < #thrill.training.tr_max_attendants
#reservation = current_user.reservations.create(reservation_params)
if #reservation
require 'Mollie/API/Client'
mollie = Mollie::API::Client.new('test_gUejkz43UkdeCauC22J6UNq')
payment = mollie.payments.create(
amount: #reservation.thrill.training.tr_price,
description: #reservation.thrill.training.tr_name,
redirect_Url: 'http://8a3a73cb.ngrok.io/your_trips',
webhookUrl: 'http://8a3a73cb.ngrok.io/notify',
metadata: {
reservationid: #reservation.id
}
)
#reservation.update_attributes payid:payment.id
redirect_to payment.payment_url
else
redirect_to #thrill.training, notice: "Helaas, de training is vol"
end
end
end

Ok, found the answer. It had to be lowercase : require 'mollie/api/client'

Related

rails i18n redis ERR unknown command [] railscast 256

Following this RailsCast : http://railscasts.com/episodes/256-i18n-backends but using Rails 5.2, I raise this error :
Redis::CommandError in Pages#home<br>
ERR unknown command '[]'
In config/initializers/i18n_backend.rb
TRANSLATION_STORE = Redis.new seems causing this problem.
Whereas TRANSLATION_STORE = {} works like a charm.
But without Redis!
Any hint?
The problem is defined here:
https://github.com/ruby-i18n/i18n/blob/master/lib/i18n/backend/key_value.rb#L25-L30
I haven't investigated redis 4 but it seems that these methods has been removed.
The solution is to patch the Redis gem and add these methods to the redis.
# config/initializers/redis.rb
class RedisHash
def initialize(redis)
#redis = redis
end
def [](key)
#redis.get(key)
end
def []=(key, value)
#redis.set(key, value)
end
end
Redis.current = Redis.new(host: 127.0.0.1,
port: 6379,
db: 0,
thread_safe: true)
# config/initializers/i18n.rb
I18n::Backend::KeyValue.new(RedisHash.new(Redis.current))
This code above is sample initializer. It works with the newest version of redis 4.3.5
I've tested also redis-store/redis-i18n and it also works with the newest redis versions but in my opinion this implementation enforces huge overload on redis.
EDIT:
Due to the redis contributors [answer][1]
[1]: https://github.com/redis/redis-rb/issues/997#issuecomment-871302883 I've updated my solution
Not a full answer I know, but I had a similar problem after upgrading redis gem from 3.3.1 to 4.0.2
I set it back to 3.3.1 and it got fixed. Odd thing for me was that the problem only occurred in the production environment.
I am using a chained backend
I18n.backend= I18n::Backend::Chain.new(
I18n::Backend::KeyValue.new(Redis.current),
I18n.backend
)

ElasticSearch 5.0 + Rails

Installed a fresh ElasticSearch 5.0 today and changed my Rails configuration to point to ES 5.
My elasticsearch.rb configuration file looks like:
require "faraday"
require "typhoeus/adapters/faraday"
config = {
host: "http://xxx.xxx.xxx.yyyy:9200/",
transport_options: {
request: { timeout: 5 }
},
}
if File.exists?("config/elasticsearch.yml")
config.merge!(YAML.load_file("config/elasticsearch.yml").symbolize_keys)
end
I have the following related gems installed on the application:
gem 'elasticsearch-model'
gem 'elasticsearch-rails'
gem 'elasticsearch-persistence', require: 'elasticsearch/persistence/model'
When I go to start my application, I receive the message:
[400] No handler found for uri [//****] and method [DELETE] (Elasticsearch::Transport::Transport::Errors::BadRequest)
Has anyone encountered this issue before?
I looked around for a bit and it looks like ElasticSearch 5.0 has a new API for deleting, but I'm not sure if this is the root cause of my issues:
https://www.elastic.co/guide/en/elasticsearch/reference/5.0/docs-delete-by-query.html
Thanks in advance!
According this discussion The problem is the proxy_options configuration. Just ignore the transport_options. If you change the configuration as following it should work.
config = {
hosts: default_host,
adapter: :typhoeus
}

Ruby XMLRPC localhost Runtime Error : Wrong Size

I am trying to connect to the XMLRPC API of a dokuwiki website.
I am successfully doing that from my own laptop, with a SSL connection, however, when I try to do it from my production server (which hosts both the wiki and the rails app from which the ruby code is executed), I run into a
Runtime Error
Wrong size. Was 163, should be 113
Here's how I initialize the connection :
#wiki = ::XMLRPC::Client.new3(
host: "wiki.example.com",
path: "/lib/exe/xmlrpc.php",
use_ssl: true)
# Temp Hack because SSL Fails
#wiki.instance_variable_get(:#http).instance_variable_set(:#verify_mode, OpenSSL::SSL::VERIFY_NONE)
end
#authenticated = false
authenticate!
end
def authenticate!
# Fails at below line :
#authenticated = #wiki.call("dokuwiki.login", ENV['WIKI_USER'], ENV['WIKI_PASSWORD'])
Rails.logger.info (#authenticated ? "Authenticated on Wiki !" : "Authentication failed on wiki !")
end
I've read many posts saying that there is a bug in the XMLRPC lib of Ruby. I was running ruby 2.1.5pxx on my laptop and ruby 1.9.xx at my server so I did a rvm install 2.1.5, yet the problem is still here
(btw, I assumed it was enough to do a rvm use 2.1.5 and then touch restart to restart my rails server, but how can I check which version of ruby it's using ?)
What is wrong ?
EDIT
On my laptop, I am running ruby 2.1.5p273 (2014-11-13 revision 48405) [x64-mingw32]
On my production server, I am running ruby-2.1.5 [ i686 ]
I tried another library, libxml-xmlrpc, and I get the following error when running the same command:
Net::HTTPBadResponse: wrong status line: "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">"
But again, the same code is running fine with the default ruby xmlrpc client on my Windows + rubyx64 2.1.5, so I really don't get it!
Edit2 : I tried adding
#wiki.http_header_extra = { "accept-encoding" => "identity" }
But then I get a
Authorization failed. HTTP-Error: 401 Unauthorized
The first call #wiki.call("dokuwiki.login", "myUsr", "myPwd") worked, but apparently it failed to authenticate me (Of course I am still using the same login information that should work)
EDIT 3
After investigation, a successful login from any other computer than localhost will set a cookie like
#cookie="DokuWiki=[small string] ; [very big string]
Whereas if I do it on localhost :
I will write [...] for random strings
#cookie="[small string 2]=deleted; DokuWiki=[small string]; [very big string]"
So I have an extra variable info stored in my cookie, which is "[small string 2]=deleted;
I believe this is what makes my authentication fails. Anyone knows what this is ???
So this localhost connection was messing up with the cookie. Apparently, even the ruby library doesn't know why, and the "Wrong size" comes from this unexpected string [random string]=deleted added at the beginning of the cookie.
Unless someone can explain WHY such a string is added, I will accept my solution of simply adding
#wiki.http_header_extra = { "accept-encoding" => "identity" }
which removes the "Wrong size" error, then
if /deleted/.match(#wiki.cookie)
#wiki.cookie = #wiki.cookie.gsub(/.*deleted; /, '')
end
To remove the beginning of the cookie

ExecJS::RuntimeError running the Getting Started with Rails blog on cygwin (windows7)

I am trying to run the Getting Started with Rails blog on cygwin (windows7). I get the following error message:
ExecJS:: RuntimeError in Welcome#index
module.js:340
throw err;
^
Error: Cannot find module 'C:\tmp\execjs20130903-50672-1vn7gqc.js'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:901:3
(in /usr/lib/ruby/gems/1.9.1/gems/turbolinks-1.3.0/lib/assets/javascripts /turbolinks.js.coffee)
node is installed.
This is after
$rails generate controller welcome index
$rails s
I am running Rails 4.0 on cygwin
Any ideas why this might be happening?
Thanks
umbregachoong
I encountered this error and it had to do with the path to the temp file being wrong. I was able to fix it by changing the following two files in \gems\[ruby version]\gems\execjs-2.0.2\lib\execjs.
(Possibly found in \usr\lib\ruby\, but that depends on how your Ruby is installed. I'm using RVM so mine is different.)
external_runtime.rb
compile_to_tempfile(source) do |file|
extract_result(#runtime.send(:exec_runtime, file.path))
end
end
should change to
compile_to_tempfile(source) do |file|
filepath = file.path
if ExecJS.cygwin? && #runtime.name == "JScript"
IO.popen("cygpath -m " + file.path) { |f| filepath = f.read }
filepath = filepath.gsub("\n","")
end
extract_result(#runtime.send(:exec_runtime, filepath))
end
end
module.rb
Add this right before the last two ends.
def cygwin?
#cygwin ||= RbConfig::CONFIG["host_os"] =~ /cygwin/
end
After this restart your Rails server and with any luck it should work.
Source: https://github.com/sstephenson/execjs/issues/78
don't do anything just go to application/assets/javascript/application.js and remove
'//'
from
//=require turbolinks
to
=require turbolinks
that will basically uncomment the line from the file
This step made my work done when i faced similar error in Default rails server going through RAILS Tutorial. I am using Windows 10 PC and this solved my case

Rails/Passenger sub URI error

I am attempting to deploy a Rails 3.0.0 application to a sub URI using passenger 2.2.15.
I believe I've made the correct RailsBaseURI changes to my http.conf , have symlinked the sub URI to the public directory of my app and added the following line of code to environments/production.rb:
config.action_controller.relative_url_root = "/sub_uri"
I've done this several times pre-rails3.0.0. That said, the app won't launch. It fails with the following Passenger error:
Error Message: wrong number of arguments(1 for 0)
Exception class: ArgumentError
/usr/lib/ruby/gems/1.8/gems/actionpack-3.0.0/lib/action_controller/railtie.rb 54 in `relative_url_root='
Is there an incompatibility between passenger 2.2.15 and rails 3.0.0 that affects sub URI's?
Any help sorting out this error is greatly appreciated.
The setter is depreciated, it's nowhere to be found in actionpack/lib/action_controller/railtie.rb.
As seen here (actionpack/lib/action_controller/depreciated/base.rb):
module ActionController
class Base
# Deprecated methods. Wrap them in a module so they can be overwritten by plugins
# (like the verify method.)
module DeprecatedBehavior #:nodoc:
def relative_url_root
ActiveSupport::Deprecation.warn "ActionController::Base.relative_url_root is ineffective. " <<
"Please stop using it.", caller
end
def relative_url_root=
ActiveSupport::Deprecation.warn "ActionController::Base.relative_url_root= is ineffective. " <<
"Please stop using it.", caller
end
end
end
end
In actionpack/lib/action_controller/metal/compatibility.rb you can see it's setter is an ENV variable:
self.config.relative_url_root = ENV['RAILS_RELATIVE_URL_ROOT']
So you need to set the ENV variable: RAILS_RELATIVE_URL_ROOT="/sub_uri"
To set the environment variable add:
SetEnv RAILS_RELATIVE_URL_ROOT /sub_uri
To the VirtualHost section (or similar) of your apache config then make sure it's being read by restarting apache and passenger.
cd <your_rails_project>
sudo apache2ctl graceful
touch tmp/restart

Resources