Calculate elements in CSV file

I am new to Ruby and now I have an issue while I try to calculate some elements. I've got 6 CSV files with the same headers and the question is how to find the total amount of payments for each payed month. 01-test.csv Payment date,Payable month,H...
more »

2017-03-18 22:03 (2) Answers

Send Email to Multiple Recepients in Ruby on Rails

I want to send Email to Student and Guardian. I have 3 tables Student,Guardian and Users. The Student and Guardian are also in User table. But when i send an email its taking the email address of the First User instead of the Guardian. This is my Cod...
more »

2017-03-18 15:03 (0) Answers

Admin user allow to delete and edit other users

I have a problem with my users-controller. Currently, an admin user can delete itself, other users can not delete themselves. In addition, each user can edit themselves. However, I would like an admin user to delete and edit itself and others. How i...
more »

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

handling time distinct from datetime

The goal is to compare timestamp to a range of times. The range of times were defined in the rails schema as t.time for postgresql database. However the data returned upon querying the console attributes a date to the record's field... start_time:...
more »

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

Ruby: Iterating through dir's and files

I wrote the following script to iterate through a directory, it's subdirectories and their files: def self.search_files_in_dir_for(dir, strings) results = {} puts "Initializing test ..." Dir.foreach(dir) do |file| ...
more »

2017-03-17 22:03 (1) Answers

IIS: drive in Serverspec

The PSDrive IIS: is not recognised as a valid path in my serverspec test. This is an example of a failing test: describe command("Get-ItemProperty -Path IIS:\\AppPools\\#{webenv}#{net2_classic_32bit_apppoolpostfix} -Name enable32BitAppOnWin64 | for...
more »

2017-03-17 17:03 (0) Answers

Keyword arguments unpacking (splat) in Ruby

What is happening below seems a little strange to me. def f(a, b) puts "#{a} :: #{b}" end f(*[1, 2], **{}) # prints "1 :: 2" hash = {} f(*[1, 2], **hash) ArgumentError: wrong number of arguments (3 for 2) f(*[1, 2], ** ArgumentError: w...
more »

2017-03-17 04:03 (3) Answers

Rubygem: How to load information of a yaml file

My gem generates the following file into config/my_gem.yml: test: true Now I want to load the value of test into my gems module to be able to call: MyGem.test => true That was my attempt: In the Rails App - config/initializers/my_gem.rb: ...
more »

2017-03-16 20:03 (2) Answers

Rails # within HTML href comments out the line

In my controller I am setting a variable equal to an HTML string in order to account for a base case. However, # comments out the rest of the line. How can I escape this? @chart_data = "<p id='chart-notice'>If you <a href="#SOME_ID">logi...
more »

2017-03-16 18:03 (2) Answers

Replace until all occurences are removed

I have the following strings: ",||||||||||||||" ",|||||a|||||,|" I would like to achieve that all occurrences of ",|" are replaced with ",," The output should be the following: ",,,,,,,,,,,,,,," ",,,,,,a|||||,," When I run .gsub(',|', ',,') on...
more »

2017-03-16 12:03 (4) Answers

How to filter Twitter API mentions

I'm creating a project using the Twitter gem and need to filter the tweets that I receive from mentions_timeline. I thought about filtering through a couple of if statements reading the text of the tweet: require 'sinatra' require 'twitter' require...
more »

2017-03-15 21:03 (2) Answers

How to fix aborting Fibonacci sequence code

I am trying to get a Fibonacci sequence of 5 million elements. This code aborts abnormally, when I pass 1000 as a parameter. def self.fibo_seq(limit) result_array = [0,1] return result_array if limit < 2 while result_array.length <= l...
more »

2017-03-15 19:03 (4) Answers

Rails form preview page

I want to save the Job data in the database, and redirect to a preview page (instead of the show page) which displays all the information from the Job form just submitted (essentially a duplicate of the show.html.erb page). Currently, when the user...
more »

2017-03-15 19:03 (2) Answers

ruby on rails, rails admin fieldset behavior

I working as intern for a webapp, they are using ruby on rails v4.2 and ruby v2.0.0, and rails admin v0.6.8. There is a problem in rails admin that arrived since Friday, after a commit, do I look on github each diff in each commit, and the problem ...
more »

2017-03-15 15:03 (0) Answers

[Fluentd]How to Unzip files in fluentd

I am trying to process log files with .gz extension in fluentd using cat_sweep plugin, and failed in my attempt. As shown in the below config, I am trying to process all files under /opt/logfiles/* location. However when the file format is .gz, cat_s...
more »

2017-03-15 14:03 (1) Answers

Breaking a loop when a user types a certain input

So I'm trying to break a loop when a user type done and from there jump into another method called "survey" that asks a few leftover questions. This is what I have a the moment: def survey puts "For how many years have you had these allergies?"...
more »

2017-03-14 20:03 (2) Answers

How to quickly join two strings in Ruby

It's common to need to join strings, and in Ruby we have common ways of doing it: appending, concatenating and interpolating one into the other, or using the built-in concat method in String. (We have multiple ways of doing it for flexibility and to ...
more »

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

Ruby: How to refactor very similar classes?

I've got a bunch of classes that are very similar to each other. The only difference is in a part of the class name, some pathes, and other classes that call, that belong in the same group. So for example I have a XDispatcher which uses a XImporter,...
more »

2017-03-14 15:03 (3) Answers