Cannot load such file -- /xsd threw by controller when adding a library - ruby-on-rails

I'm trying to load a library from a Controller and it is throwing me this error
cannot load such file -- /xsd
It is, in fact, being loaded in the first line of the library file
require 'xsd/qname'
# {http://www.f2b.com.br/soap/wsbillingaction.xsd}F2bAcaoCobranca
# mensagem - F2bAcaoCobranca::Mensagem
# cliente - F2bAcaoCobranca::Cliente
# acao_cobranca - F2bAcaoCobranca::Acao_cobranca
class F2bAcaoCobranca
#...
end
The library's file is in the following directory:
lib
--f2b
--acao_cobranca
--wsbillingaction.rb
And my controller's action has the following lines of code
def index
require 'f2b/acao_cobranca/wsbillingaction.rb'
end
What is giving me this error? Is it some old stuff from previous versions of Ruby/Rails? How can I fix it?

wsbillingaction depend on another lib (xsd/qname), you should include it in your project or install it as a gem

Related

Override method from gem package in Rails application

I am using the package and initialise it in my rails application in config/initializers/prawn_rails.rb with include PrawnRailsForms
I am trying to override a method to increase the font size of field.upcase with the code below
include PrawnRailsForms
DocumentExtensions.module_eval do
def make_field_box(field)
stroke_bounds
bounds.add_left_padding 2
move_down 2
text field.upcase, size: 18
end
end
But the font doesn't get affected in the pdf views even I restarted the server.
You need to do the monkey pathing here.
Create a prawn-rails-forms directory in lib directory.
Create a document_extensions.rb file inside prawn-rails-forms directory.
Add below code to the document_extensions.rb
module PrawnRailsForms
module DocumentExtensions
private
def make_field_box(field)
stroke_bounds
bounds.add_left_padding 2
move_down 2
text field.upcase, size: 8
end
end
end
Restart the server.
Extended
If you find still not working after restarting the server then
Add config.autoload_paths += %W(#{config.root}/lib) to the config/application.rb OR
Move prawn-rails-forms directory to the config/initializers
Please let me know if it works for you.

Rails 5 gem gon not recognize jbuilder file

I have implemented rails gem gon in index method and it works fine. But when I try to implement in controller#new it is not working this is my error output:
No such file or directory # rb_sysopen - app/views/cuenta_proveedors/new.json.jbuilder
but i have already create this file.
this is my controller
def new
#cuenta_proveedor = CuentaProveedor.new
#cuentas = #negocio.cuenta_proveedors.order(:created_at)
gon.jbuilder // THIS LINE CAUSE THE ERROR SHOWN BY APPLICATION TRACE
end
i have the created the file new.json.jbuiler
json.cuenta_proveedores #cuentas do |cc|
json.proveedor cc.proveedor.nombre
json.inicial cc.monto_inicial
json.saldo cc.monto_adeudado
json.observacion cc.observacion
json.token cc.token
end
Why is this happening? I can not found any logic to this error. If you need more information ask me . Thanks

Illegal nesting with SASS everytime

I’m trying to create my own website and I’m using Nanoc. I’m also writing my files in HAML and SASS.
When I’m writing into my SASS file, I always have the error
Haml::SyntaxError: Illegal nesting: nesting within plain text is illegal
when I compile (nanoc compile).
My sass files are in /content/css and I would like they go in /output/css
The thing I don’t understand is that if I put spaces or if I put a tab, it doesn’t compile. The only thing which works is when I don’t put any spaces or tabs. It compiles but the CSS in output doesn’t work.
I looked here before : https://groups.google.com/forum/#!topic/nanoc/UI4VccZCDD4 but it doesn't correct my compilation error.
I let my style.sass file and my Rules file below.
What is causing this issue and how can I resolve it?
div.title
width: 80%
background-color: #b7b8b2
If I put no spaces before width and background, it compiles but doesn't work.
#!/usr/bin/env ruby
require 'compass'
Compass.add_project_configuration 'config.rb' # when using Compass 0.10
### Compile rules
compile '/content/css/*' do
filter :sass, Compass.sass_engine_options # add the second parameter for Compass
end
compile '*' do
if item.binary?
# don’t filter binary items
else
filter :haml
layout 'default'
end
end
### Route rules
route '/content/css/*' do
#'/style.css'
# item.identifier.chop + '.css' #so that the /content/stylesheet.sass item is compiled in sass
unless item.identifier.start_with?('/content/css/_') # for partials
item.identifier.gsub(/\/$/, '') + '.css'
end
end
route '*' do
if item.binary?
# Write item with identifier /foo/ to /foo.ext
item.identifier.chop + '.' + item[:extension]
else
# Write item with identifier /foo/ to /foo/index.html
item.identifier + 'index.html'
end
end
### Layout rules
layout '*', :haml
The CSS compilation rule has an error. It should say
compile '/css/*'
instead of
compile '/content/css/*'
Item identifiers do not start with /content.

How to test a Rack::Directory serving static files with Capybara? or How to test Rack Middleware with Capybara?

I'm using Rack::Directory.new to map a directory in the public folder directly to the website and serve static files.
My config.ru contains:
map '/pdfs/' do
run Rack::Directory.new('./public/resources/pdfs')
end
require './app/main.rb'
run MainSinatra
I'm using a Sinatra App to run the rest of the application and using cucumber-sinatra to pre-generate some files.
When I try to load the path to the pdfs in my paths file I get an error.
features/support/paths.rb:
def path_to(page_name)
case page_name
when /dias_all/
'/pdfs'
...
end
Then on my steps file I put
visit dias_all
and I get a 404 error.
I tried adding this to the features/support/env.rb file but still got an error:
class MainSinatraWorld
...
include Rack::Test::Methods
def app
Rack::Directory.new('./public/resources/pdfs')
end
end
and then changed the step file visit to a get, but still got an error.
get('/pdfs/dias')
error:
No response yet. Request a page first. (Rack::Test::Error)
How do I test the contents of the folder through Capybara or Cucumber?
I was able to figure out how to solve this problem by changing this line in env.rb from:
Capybara.app = MainSinatra
to:
Capybara.app = eval "Rack::Builder.new {( " + File.read(File.dirname(__FILE__) +
'/../../config.ru') + "\n )}"
And this runs the application from the rack up file (config.ru) and loads all the middleware that wasn't otherwise loading.
I found the answer in this blog.

Loading yaml from file and join fails

I try to load a yaml file into an array but it fails with undefined method `join' for "a b c":String
# Check certain temporarily emails
# Throw notice not accepted use other email
require 'yaml'
bad_hostnames = YAML::load(File.read("#{Rails.root}/config/bad_hosts.yml"))
if /^(#{bad_hostnames.join("|")})$/.match(host)
errors.add(:email, "Please not use a disposable mailbox")
end
So i required yaml before and on top of the model, controller where I load the yml in:
require 'yaml'
Still same result, in rails console this works flawlessly, what am I missing?
The above code is inside my user.rb model, in console it works
EDIT:
bad_hosts.yml looks like (shortened) 1 provider the line
0-mail.com
10minutemail.com
30minutemail.com
4warding.net
Your .yml file is not a YAML file.
This would make it .yml file.
- 0-mail.com
- 10minutemail.com
- 30minutemail.com
- 4warding.net
But when you want to load just a file line by line try the following:
lines = IO.readlines("#{Rails.root}/config/bad_hosts.yml")
# note: lines end in "\n"

Resources