Asynchronous API call to update model in Rails

I am making a simple API call to Coinbase's API to get the current buy/sell price of bitcoin. I have a before_save action on my Price model class PriceBtc < ApplicationRecord before_save :save_prices def save_prices = PriceBtc.get_...
more »

2017-12-03 21:12 (1) Answers

Getting all unique URL's using nokogiri

I've been working for a while to try to use the .uniq method to generate a unique list of URL's from a website (within the /informatics path). No matter what I try I get a method error when trying to generate the list. I'm sure it's a syntax issue,...
more »

2017-12-03 18:12 (1) Answers

Issues with High Sierra 10.13.1 and Rails?

I've tried installing Rails on a high sierra but keep receiving a "Failed to build gem native extension" error. checking for sys/epoll.h... no ^ This is what I need to be looking at. I'm not sure if this is an issue with the new OS...possibly an i...
more »

2017-12-03 07:12 (1) Answers

How to display websites in iframe

I am using ruby and sinatra. I need to create a website that allows the user to upload a zipfile of other websites and display all of them in multiple iframes on the page but I'm not sure how to even start this. so far I have made the website that ...
more »

2017-12-02 22:12 (0) Answers

Cannot create FactoryGirl's factory for model

I have this situation with legacy project. Suppose I have rails model: rails g model entity name:string In that model there is MAIN_ENTITY constant: class Entity < ActiveRecord::Base MAIN_ENTITY_ID = 1 MAIN_ENTITY = Entity.find(MAIN_ENT...
more »

2017-12-02 13:12 (1) Answers

Why does YARD require parameters to be named?

I've just started using YARD to document Ruby code and am very new to how it works. Forgive me if this is a basic question that has been asked before but I can't find any answer to it. If I document my code like the following example and run yardoc ...
more »

2017-12-02 13:12 (0) Answers

Does Array#sample guarantee random order?

Does it only guarantee a random subset, or also random order? Use case is generating a secret string with ('a'..'z').to_a.sample(8).join. I'd like to know whether I can trust that all 26⋅25⋅24⋅23⋅22⋅21⋅20⋅19 possib...
more »

2017-12-01 21:12 (3) Answers

Ruby - Check URL for specific in-page result

I am a total newbie and worked out a ruby file that allows to check websites if they are live or if they return a 404 error. It looks like this: #!/usr/bin/env ruby # encoding: utf-8 urls = %w(
more »

2017-12-01 12:12 (1) Answers

Gem needs to be required manually

I've created a gem. You can see the full source code here: (in any case, not advertising) However, when I use it in the Rails project # Gemfile gem 'instagram_api_client' it doesn't work untill a manual...
more »

2017-12-01 10:12 (1) Answers

Ruby test raise_if_conflicts error

I created sample_test.rb to run Minitest. require 'minitest/autorun' class SampleTest < Minitest::Test def test_sample assert_equal 'RUBY', 'ruby'.upcase end end I tried to run sample_test.rb but I got this error. Users/xxxxx/.rbenv/v...
more »

2017-12-01 08:12 (1) Answers

How does the inject method work?

I am a beginner in Ruby and I came across a code snippet which had the following: def add(*nums) nums.inject(&:+) end Examples: add(1, 2) #=> 3 add(1, 2, 3, 4) #=> 10 How does the code snippet work? ...
more »

2017-12-01 01:12 (3) Answers

Find by Selector Style Scraping

I'm doing a "Scraper" for my university and I need to select all the "tbody" that contain the "background color: #bebeff". I tried several of the w3schools Selectors and I can not do it. Is there any way to do that ?. Image By the way, I use Mechan...
more »

2017-11-30 19:11 (1) Answers

How to get size of cloned lazy enumerator

We have an Enumerator::Lazy object a = [1,2,3] {} #=> <Enumerator::Lazy: #<Enumerator::Lazy: [1, 2, 3]>:map> a.size #=> 3 a.clone.size #=> nil Does anyone have correct explanation of such behaviour ? I know that size ...
more »

2017-11-30 17:11 (1) Answers

Ruby Search Array of Hashes and Arrays

I have an array of hashes which also include an array: machines = [{ 'name' => 'ldapserver1', 'ip' => '', 'role' => ['server', 'initial'] }, { 'name' => 'ldapserver2', 'ip' => '', 'role' ...
more »

2017-11-29 18:11 (3) Answers

Rails 5 Migration Data Type Issue

I originally developed my rails 5 application using PostgreSQL. I had to change over to a MariaDB after I had done all of my development due to some issues with hosting. I'm trying to put in an update that adds a reference to the admin from my shop...
more »

2017-11-29 16:11 (1) Answers

Ruby: What does binds mean in ActiveRecord gem?

I saw binds as argument in lots of methods, but without any documentation. e.g. Rails Source code def find_by_sql(sql, binds = [], preparable: nil, &block) result_set = connection.select_all(sanitize_sql(sql), "#{name} Load", binds, preparab...
more »

2017-11-29 07:11 (1) Answers