I have been trying to add image uploading and displaying feature to my web app, and decided to use Active Storage following this documentation: https://edgeguides.rubyonrails.org/active_storage_overview.html. I know libvips would be faster, but I decided to use ImageMagick because it is widely used. However, after following all the steps, when I visit some pages that display image, I am stuck and the page is loading forever. Terminal displays following message:
17:44:28 web.1 | ↳ app/models/product.rb:65:in `block in images_as_thumbnail'
17:44:28 web.1 | Disk Storage (12.4ms) Downloaded file from key: 53x4a0bwrpa7si019zkg7vqp303j
For images_as_thumbnail, the definition is:
def images_as_thumbnail
images.map do |image|
image.variant(resize_to_limit: [150, 150]).processed
end
end
It sometimes work, but it gets stuck pretty often. Does anyone know what might be causing problem here?
Related
I am trying to get some basic information from the Steam Community via the steam-condenser gem and so far the Steam.new seems to work just fine with all the players information.
however when I do this (example)
player = SteamId.new("tiger")
stats = player.fetch_games
I get the following error message
Traceback (most recent call last):
1: from lib/assets/ruby/test.rb:15:in `<main>'
/home/zigs/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/steam-condenser-1.3.11/lib/steam/community/steam_id.rb:326:in `fetch_games': undefined method `[]' for nil:NilClass (NoMethodError)
A lot of the information I need seems to be connected to the fetch_games (for example the method total_playtime(id))
Not sure why this is not working. I am lost. Any help or ideas are highly appreciated! Thank you!
TLDR; it looks like this gem no longer works.
the particular module that you're having trouble with is:
def fetch_games
games_data = parse "#{base_url}/games?xml=1"
#games = {}
#recent_playtimes = {}
#total_playtimes = {}
games_data['games']['game'].each do |game_data|
app_id = game_data['appID'].to_i
#games[app_id] = SteamGame.new app_id, game_data
recent = game_data['hoursLast2Weeks'].to_f
total = (game_data['hoursOnRecord'] || '').delete(',').to_f
#recent_playtimes[app_id] = (recent * 60).to_i
#total_playtimes[app_id] = (total * 60).to_i
end
true
end
with the particular problem statement being games_data['games']['game'].each
If we were looking to get information for a particular user, it downloads an XML document about the user from a URL looking like:
http://steamcommunity.com/id/demomenz?xml=1
and this file does not seem to contain any games objects in it.
Having looked at the codebase for the steam-condenser gem; it hasn't really been updated in about 6 years. I can only assume that the XML format has been modified since this time and that the gem will no longer work.
Valve has added more privacy options to Steam Community profiles which are not reflected in the old XML APIs.
Apparently, the profile in question (tiger) has it‘s game details set to “Friends Only” or ”Private” as games are also unavailable in the browser.
The code from the released 1.x versions is no longer guaranteed to work when it comes to Steam Community. Valve deprecated the old XML APIs several years ago. Sadly, the modern Web API hasn‘t gotten much attention from Valve‘s side either. So development of Steam Condenser has mostly come to halt, too.
You might have more luck using the code from the master branch of the GitHub repository which uses Web API for most of the Community features.
You will have to register for a Steam Web API key, though: https://steamcommunity.com/dev/apikey
I'm building a web-based log parser system using Ruby on Rails. I already finished the function for uploading log files and I also already have the Regex Expression for capturing the information that I need from each log file entry. As you know, a log file may contain thousands of log file entries and they usually follow the same pattern.
For instance:
Processing NameofController#index (for 999.999.999.999 at 2019-01-24 00:12:00) [GET]
Session ID: aaaaaabbbbbbcccccc11112222333
Parameters: {"controller"=>"sample_invoices", "action"=>"index",
"before"=>"2019-01-24T12:00:00Z", "soap_id"=>"0001",
"s"=>"sample", "format"=>"xml"}
Sample chain halted as [:example] rendered_or_redirected.
Completed in 0.00022 (4588 reqs/sec) | Rendering: 0.00010 (44%) | DB: 0.00000 (0%) | 401 Unauthorized [http://www.iwantsoaps.com/pages/sample.xml?s=sample&soap_id=0001&before=2019-01-24T12:00:00Z]
Can someone recommend a way for me to read each log file using regex after they have been uploaded? I simply don't know where to start. I need to store the captured values inside a database as well.
In Ruby on Rails, when I run the rails server, the very first request seems to be extremely slow, the logs show that the slowness comes from the view rendering:
2017-08-14 10:24:12.707 [ 22139] [INFO ] Completed 200 OK in 18547ms (Views: 18501.6ms | ActiveRecord: 3.7ms)
I assume it's because it needs to connect to the database. The next request is of course, fast(er):
2017-08-14 11:01:54.937 [ 25662] [INFO ] Completed 200 OK in 765ms (Views: 714.0ms | ActiveRecord: 8.3ms)
I assume this has something to do with the cache, and it already has a database connection. I've tried to restart my server, restart the database, clear my browser cache and rake db:sessions:clear, but I am unable to get the first request to go slow again in development.
Here's where things get interesting. Every single time I run the cucumber tests, the very first request is always incredibly slow:
2017-08-14 11:19:52.879 [ 27729] [INFO ] Completed 200 OK in 38326ms (Views: 38306.8ms | ActiveRecord: 6.1ms)
It's even longer than it is in development for unknown reasons.
What is different between restarting the Rails server and re-running a test that makes the first request of the tests so slow? What steps can I take to troubleshoot such an issue?
(It's no fun waiting 30 seconds every time we want to run one of our cucumber tests)
Unfortunately the answer was extremely isolated to our code, but I wanted to share the answer in-case anyone else ever ran into this situation.
I noticed that if I ran rake tmp:cache:clear the first request in the browser would be really slow again. I investigated that command and saw it cleared out the #{Rails.root}/tmp directory.
I then found this line in the Cucumber env.rb:
Dir.foreach("#{Rails.root}/tmp") { |f|
FileUtils.rm_rf("#{Rails.root}/tmp/#{f}")
}
That appeared to be the culprit the entire time. I don't know why that was added (3 years ago...)
We have a main portal site (running Rails 4 with a PostgreSQL database), and an external image server (running Node.js with Mongo database). I'm trying to establish a connection from Rails to the database - I installed the mongo gem - https://docs.mongodb.org/ecosystem/drivers/ruby/ - and have been following the guide, but got stuck on an odd key error that I can't seem to find any information on.
The image server itself is running fine with no problems (it has a GUI interface that is working fine).
In my controller (I changed the names and left out the passwords):
image_server = Mongo::Client.new([ 'image.companyname.com:####' ], :database => 'db-name')
It seems to connect:
D, [2015-11-11T00:41:22.730360 #9410] DEBUG -- : MONGODB | Adding image.companyname.com:#### to the cluster.
But then just spams this message over and over (and queries don't do anything but return this error even faster).
D, [2015-11-11T00:41:22.991386 #9410] DEBUG -- : MONGODB | key not found: "t"
Eventually it returns one error message as well, but keeps spamming the key not found error as well:
Mongo::Error::NoServerAvailable (No server is available matching preference: #<Mongo::ServerSelector::Primary:0x007f5a943f6ee8 #options={"mode"=>:primary, "database"=>"db-name"}, #tag_sets=[], #server_selection_timeout=30>):
app/controllers/admin/model_controller.rb:9:in `index'
EDIT
I even tried connect directly to the UNIX socket, and got the same error:
image_server = Mongo::Client.new('mongodb://image.companyname.com:####/path/to/socket/socketname.sock')
END EDIT
I'm unsure what the heck this 'key not found "t"' error is, or how to even begin to diagnose this. I've messed with every single connection option I can think of, and nothing changes. Any ideas?
I am trying to take the Evernote Ruby example https://github.com/evernote/evernote-sdk-ruby which uses Sinatra and integrate it into Rails.
I have everything working fine until pulling a list of notebooks in the callback.
notebooks = noteStore.listNotebooks(access_token.token)
result = Array.new
notebooks.each do |notebook|
result << notebook.name
end
#notebooks = result
It's getting this error: (which isn't helpful at all)
RuntimeError in CallbacksController#callback
--- !binary |-
U1NMX2Nvbm5lY3QgcmV0dXJuZWQ9MSBlcnJubz0wIHN0YXRlPVNTTHYzIHJl
YWQgc2VydmVyIGNlcnRpZmljYXRlIEI6IGNlcnRpZmljYXRlIHZlcmlmeSBm
YWlsZWQ=
The Sinatra app works correctly. So my guess is that some file is not being loaded to parse this. But I have tried everything.
I will post the full controller here: http://paste.codebasehq.com/pastes/7frtcdhyncwb0emznj
Thanks for the help.
I guess to_yml makes your error message unreadable like:
--- !binary |-
U1NMX2Nvbm5lY3QgcmV0dXJuZWQ9MSBlcnJubz0wIHN0YXRlPVNTTHYzIHJl
YWQgc2VydmVyIGNlcnRpZmljYXRlIEI6IGNlcnRpZmljYXRlIHZlcmlmeSBm
YWlsZWQ=
Can you replace to_yml with inspect?
It seems simply your message is outputted as binary and you could figure out the cause of error from messages if it is outputted as text.
Related post:
Thor & YAML outputting as binary?