0

I am trying to concatenate the ":" sign with value that is inside a variable but when trying to concatenate it shows me the following error: bad URI(is not URI?): :208

This is the code I am trying to concatenate in the ApplicationController:

  def set_database

    if usuario_signed_in?
      empresa = ':'+(current_usuario.empresa_id)
      ActiveRecord::Base.establish_connection(empresa)

  end

With the previous code does not work, but replacing the variable as follows does not show the error:

if usuario_signed_in?
  empresa = :'208'
  ActiveRecord::Base.establish_connection(empresa)
end
LuisC
  • 335
  • 1
  • 11

2 Answers2

1

yeah those are 2 different things

empresa = ':'+(current_usuario.empresa_id)

would probably resolve to a string or an error while

empresa = :'208'

is a symbol.

I believe you can solve this issue by just converting your empresa to a symbol, either by calling

current_usuario.empresa_id.to_sym 

OR

current_usuario.empresa_id.to_s.to_sym
oreoluwa
  • 5,553
  • 2
  • 20
  • 27
  • my assumption is that you're getting the right results with the second portion of your code – oreoluwa Mar 03 '17 at 22:31
  • Thank you very much, that worked perfectly with your second option. But I can not understand, how is :'208' a symbol? And just put empresa = (current_usuario.empresa_id).to_s.to_sym do not need to put ':' at the beginning – LuisC Mar 03 '17 at 22:46
0

The error is telling you the URL is not valid, you need to encode it and parse it. See How to fix bad URI is not URI

Community
  • 1
  • 1
SYoung82
  • 33
  • 1
  • 6