I'm using Rails 5.2.5 and I want to change the log level when I use rails console.
I want to stress that I don't want to change any file in the project, but just to do the change from the console.
I saw some suggestions to run:
conf.log_level = :debug
in the console, but I got the error
NameError (undefined local variable or method `config' for
main:Object) Did you mean? conf
I also tried to execute
conf.log_level = :debug
but I also got the error:
Traceback (most recent call last):
2: from (irb):11
1: from (irb):11:in `rescue in irb_binding'
Do you have any suggestion?
Change YourApp configuration (YourApplocated at config/environment/[environment].rb
YourApp.configure do
config.log_level = :info
end
Or you can use Rails.application.configure
2.5.8 :005 > Rails.application.configure do
2.5.8 :006 > puts(config.log_level)
2.5.8 :007?> end
debug
=> nil
2.5.8 :008 > Rails.application.configure do
2.5.8 :009 > config.log_level = :info
2.5.8 :010?> end
=> :info
2.5.8 :011 > Rails.application.configure do
2.5.8 :012 > puts(config.log_level)
2.5.8 :013?> end
info
Related
I'm using watir in my Rails application.
I did simple commands and got a error:
2.3.0 :001 > require 'watir-webdriver'
/home/user/.rvm/gems/ruby-2.3.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `require': `require "watir-webdriver"` is deprecated. Please, use `require "watir"`.
=> true
2.3.0 :002 > browser = Watir::Browser.new
NoMethodError: undefined method `[]' for nil:NilClass
from (irb):2:in `new'
from (irb):2
I need any help or suggestions on this point, thanks.
By default Watir is using chromedriver
I'm trying to connect to my remote mongoDB database through irb shell.
I ran the following:
2.3.0 :001 > require 'mongo'
=> true
2.3.0 :002 > Mongo::Logger.logger.level = ::Logger::INFO
=> 1
2.3.0 :003 > require 'uri'
=> false
The last statement should return true. I attempted to initialise the client after this via:
db = Mongo::Client.new(ENV['MLAB_URI'])
And got the error:
NoMethodError: undefined method `each' for nil:NilClass
I think you haven't set the ENV variable .
check ENV['MLAB_URI'] variable value.
I have rails 4.2.1 installed.
On my local rails console:
2.2.1 :001 > require 'nokogiri'
=> true
2.2.1 :002 > require 'open-uri'
=> true
2.2.1 :003 > doc = Nokogiri::HTML(open('http://sfbay.craigslist.org/search/fuo?srchType=T&query=knoll'))
And the response time is ~ 1s.
On the heroku rails console, I just run:
doc = Nokogiri::HTML(open('http://sfbay.craigslist.org/search/fuo?srchType=T&query=knoll'))
And the response time is over 30s.
I get what I'm expecting in both places, but the response time on Heroku causes my app to time out in production.
I'm using the SNMP gem in a Rails app to control a Cisco switch. The "get" features of the Gem work, and I can retrieve values from the devices, but the "set" feature isn't working so well...
From the command line, the SNMP commands work properly:
bash-4.1# snmpset -v2c -c private-string 192.168.3.1 .1.3.6.1.2.1.2.2.1.7.11 i 2
IF-MIB::ifAdminStatus.11 = INTEGER: down(2)
bash-4.1#
But when I try to set the same OID using the Gem, I get "no response from 192.168.3.1"
In both the actual app and in IRB:
bash-4.1# irb
2.0.0-p0 :001 > require 'snmp'
=> true
2.0.0-p0 :002 > include SNMP
=> Object
2.0.0-p0 :003 > SNMP::Manager.open(:host => "192.168.3.1", :community => "private-string") do |manager|
2.0.0-p0 :004 > varbind = VarBind.new("1.3.6.1.2.1.2.2.1.7.11", "2")
2.0.0-p0 :005?> manager.set(varbind)
2.0.0-p0 :006?> end
SNMP::RequestTimeout: host 192.168.3.1 not responding
from /usr/local/rvm/gems/ruby-2.0.0-p0/gems/snmp-1.1.1/lib/snmp/manager.rb:293:in `set'
from (irb):5:in `block in irb_binding'
from /usr/local/rvm/gems/ruby-2.0.0-p0/gems/snmp-1.1.1/lib/snmp/manager.rb:205:in `open'
from (irb):3
from /usr/local/rvm/rubies/ruby-2.0.0-p0/bin/irb:16:in `<main>'
2.0.0-p0 :007 > exit
I can run the snmpset from the command line on the same machine, and it works correctly, but not using the gem.
Try varbind = VarBind.new("1.3.6.1.2.1.2.2.1.7.11", SNMP::Integer.new(2)) so that the varbind type is correct.
i have some problem with removing diacritics with iconv in ruby on rails
here is my code:
class Diacritics
def removeDiacritics(text)
dRemover = Iconv.new("ASCII//TRANSLIT", "UTF-8")
text = dRemover.iconv(text).gsub(/[^a-zA-Z0-9 ]/, '')
end
end
this is output:
1.9.3-p392 :001 > require "diacritics"
/usr/local/rvm/gems/ruby-1.9.3-p392#persoc/gems/activesupport-3.2.12/lib/active_support/dependencies.rb:251:in `block in require': iconv will be deprecated in the future, use String#encode instead.
=> true
1.9.3-p392 :002 > remover = Diacritics.new
=> #<Diacritics:0x00000004237068>
1.9.3-p392 :003 > text = "Dánský prezídent"
=> "Dánský prezídent"
1.9.3-p392 :004 > remover.removeDiacritics(text)
=> "Dnsk prezdent"
i expect "Dansky prezident"
server apache on fedora (httpd), using rvm and ruby 1.9.3-p392
Can anybody help me?
You can use the ActiveSupport::Inflector.transliterate method.
ActiveSupport::Inflector.transliterate("Dánsky prezídent") # => "Dansky prezident"
If you need this for a url slug, it's even easier.
"Dánsky prezídent".parameterize # => "dansky-prezident"