• Connect to 2 databases from same model in Rails 2019-03-04

    I have an application that run in 2 different countries. Lets say US and Brazil. I have a User Model that connects to US or Brazil depending on a param passed by calling: User.establish_connection("Brazil_DB") User.establish_connection("US_

    Tags: ruby, ruby on rails 4
  • Why doesn't ---.*- select everything between - inclusive? 2019-03-02

    I have a text file that looks like this: Some text here. This text is not replaced. --- And then a wild block appears! It has stuff in it that I'm trying to replace. --- The block is no more. Nothing to replace here. And I'd like to replace everythin

    Tags: ruby, regex
  • Is while loop a good practice for cronjob alternative 2019-02-27

    I want to run the following task as a daemon (infinite loop) restart the docker containers and its tasks every 6:00 and 12:00 while true docker-compose up docker exec EZUSer_star_1 ruby star/star.rb& docker exec EZUSer_tiger_1 ruby tiger/tiger.rb&

    Tags: ruby
  • How to get return value from a forked / spawned process in Ruby? 2019-02-12

    My simple test program: pid = Process.spawn("sleep 10;date") How can I place the output (eg stdout) of the "date" command in a variable when it is available? I don't want to use a file for the data exchange. --------------Solutions----

    Tags: ruby, process, fork, output, spawn
  • How can I get token and login values from string via regex? 2019-01-01

    I have a string: "Token token="ZuS6HNdwXsCDo2Moq2nx", login="login.login"" I want to get ZuS6HNdwXsCDo2Moq2nx and login.login. How can I get token and login values using regexp? I use /"\w+"/ to get token value, but

    Tags: ruby, regex, string
  • Is Ruby cucumber thread-safe? 2018-11-27

    I am currently trying to implement multi-threading using Ruby Cucumber and i am just wondering whether Cucumber is thread-safe or not? I am invoking the cucumber main class to run tests rather than using the command. I am not using parallel_tests gem

    Tags: ruby, gem, multithreading, cucumber
  • Mongoid querys memory limit 2018-10-14

    I have around 1 million records in my database. When I do: MyModel.distinct(:my_field) getting this error - failed with error 17217: "exception: distinct too big, 16mb cap" Tried to do it via aggregation - getting the same error. group = {"

    Tags: ruby, mongodb, mongoid
  • Minitest mocking Sinatra app 2018-10-06

    I have Sinatra app inherited from Sinatra::Base class. In this app I have one helper method which I use in before filter. How to mock such method in tests using minitest mock library? before do unless valid_signature? halt 401 end end --------------S

    Tags: ruby, mocking, sinatra, minitest
  • MiniMagick Wrong Command when Covert PDF to PNG? 2018-08-30

    I using MiniMagick gems. And I am currently doing this: do |convert| convert << input convert << '-verbose' convert << '-density' << 720 convert << '-quality' << 100 convert << '-colo

    Tags: ruby, graphicsmagick, minimagick
  • Cannot install Ruby-Mapnik 2018-08-29

    I'm trying to install Ruby-Mapnik with no luck. Before this, I installed Mapnik version 3.0.0-pre with success. $ mapnik-config -v 3.0.0-pre So. First I tried to install the gem, but got it wrong: $ sudo gem install ruby_mapnik Fetching: rice-1.7.0.g

    Tags: ruby, gem, installation, mapnik
  • Facebook Grouping related posts reading from Ruby program using Koala 2018-08-25

    I am implementing a ruby program to automatically read birthday posts from facebook timeline. I am using the Koala library. A short version of my code can be found here - In the response feed instea

    Tags: ruby, facebook graph api, koala
  • Encountering probles install cocoapods (Xcode) 2018-08-13

    I'm having issues installing cocoa pods to my college's computer. I talked to the technical director for the CS department, who used admin privileges to SSH into my computer and install cocoa pods. However, when I try to call pod install onto the dir

    Tags: ruby, xcode, cocoapods
  • Prevent conditional checking on Hash to create Key 2018-07-18

    Whenever I run a conditional checking on Hash to see if a key doesn't have any value, it creates that key x = {|h,k| h[k] = []} puts x >>>>{} if x[0] == [] puts "Ok" end >>>>Ok puts x >>>> {0=>[]}

    Tags: ruby
  • Two files are found in WATIR-Classic 3.0.0 but not in WATIR-Classic 3.7.0 2018-06-25

    I can find two files named 'testcase.rb' and 'assertions.rb' in WATIR-CLASSIC 3.0.0, but those two files are not found in WATIR-CLASSIC 3.7.0. What is the reason for this? Or is it found in some other folder? --------------Solutions------------- In w

    Tags: ruby, watir, watir classic
  • Ruby: How to generate direct access keys to nested hash which contains hash & arrays as values? 2018-05-30

    I was happened to compare 2 xml files where one is input xml and the other one is output xml. I am converting both the xml into hash. My Idea is to get all the keys from input hash(input xml converted to hash) like above and search each key in the bo

    Tags: ruby
  • Ruby interpreted variables is_a? 2018-05-13

    I am looking to check a variabe for its type based on the value held in another variable but am struggling with it. I'm completely new to ruby but can anyone tell me how to have the value of a variable interpreted in the expression? My current code l

    Tags: ruby, variable types
  • Dynamic parameters for method 2018-05-07

    I have some normal set methods for a class which i want to call from a dynamic context. But i am having trouble with building up the method call from variables. Example code setters def set_name(value) @name = value end def set_size(value) @size = va

    Tags: ruby, metaprogramming, dynamic programming
  • Building a JSON string from act_as_tree tree 2018-04-28

    I am new in learning Ruby. In a program, I have used acts_as_tree to build an organization tree from a hierarchical table. Now, I wish to build a JSON string from the data contained in tree nodes. In the JSON output, each parent node will have an att

    Tags: ruby
  • drying a block using proc in Ruby 2.2 2018-04-26

    I have a piece of code that I would like to DRY up: def start queue1.pop_all do |record| # some non-trivial logic end queue2.subscribe_one do |record| # the same set of non-trivial logic end end One way I have come up is to create a private method th

    Tags: ruby
  • Else part is not working in Rails ajax form 2018-03-05

    I have a Rails ajax form to submit.When user will give the correct data it will search the database and do the operation accordingly.If user is giving the Wrong data it should display user to alert message.But it is not happening like that. I am expl

    Tags: ruby, ajax, ruby on rails 3.2

Copyright (C), All Rights Reserved.

processed in 0.156 (s). 7 q(s)