Ruby is a multi-platform open-source, dynamic object-oriented interpreted language, created by Yukihiro Matsumoto (Matz) in 1995. The [ruby] tag is for questions related to the Ruby language, including its syntax and its libraries. Questions specifically about the Ruby on Rails framework should be ...

learn more… | top users | synonyms | ruby jobs

1
vote
0answers
16 views

Get the last and the previous “gold_id” of the previous day with mongo

I have this kind of data : {"_id"=>BSON::ObjectId('560b5c5d80ec9700030035dc'), "active"=>true, "user_id"=>nil, "action"=>"connection", "shop_id"=>245929, "gold_id"=>23452349, "...
0
votes
1answer
13 views

Apache2 not handling high traffic (with Ruby on Rails site)

Hi I have devloped a website in Ruby on Rails and configured it with apache2 and passenger, normally the site working very smooth but when it get traffic then it slow very down and most time it ...
0
votes
2answers
11 views

Undefined method `embroderies' for nil:NilClass for submit create form

I set up submit form to add new data, but I got this error undefined methodembroderies' for nil:NilClass.` I was following the rails guide for that but I have no idea how can I correct my code. Here ...
0
votes
3answers
32 views

Ruby hash returning strange values

I am returning a response of user fields in JSON. I am creating JSON as below. def user_response(users) users_array = [] users.each do |user| uhash = {} uhash[:id] = user.id, ...
0
votes
1answer
13 views

Geocoder gem 'rake geocode:all CLASS=Model' not working

I have a RoR app with geocoder gem installed. I am trying to bulk geocode all rows (approx. 2500) in my database with rake geocode:all. When I run the command nothing happened. None of the rows were ...
0
votes
1answer
11 views

Auto upgrade Gem Versions in GemFile with Rails upgrade

I'm upgrading my Rails application to 5.0 (5.0.0.1 current latest), I've also upgraded my Ruby version to 2.3.0p0 and bundler version to 1.13.6, Now when I run bundle update it throws error like ...
0
votes
4answers
29 views

Combine First and Last name into single field in RubyonRails

I have only one field in database "User_Name", I need to persist the combination of first and last name into that field. I am getting issue in this line <%= f.text_field(:firstName, params[:...
0
votes
1answer
19 views

Get dates Queries with arel and gt lt between methods in rails

I want to get dates greater than one specific date,or smaller than that or even dates between two given dates with arel.this is my controller: @from_time = search[:value][:from_time] @to_time = ...
-2
votes
0answers
12 views

ruby dry run No such file or directory /platform-tools/adb (Errno::ENOENT)

how can i fix this problem ? when i using dryrun. log is here. ➜ ~ dryrun git@github.com:cesarferreira/android-helloworld.git Searching for devices... /Users/baidu/.rvm/rubies/ruby-2.0.0-...
2
votes
2answers
29 views

How to exclude the floats from the factorial method in Ruby?

When finding factorial, using recursion(Ruby), following code finds the factorial of the whole numbers but fails in cases of floats. How can I tweak this? I thought about using domains like in Maths ...
0
votes
0answers
9 views

undefined method `to_model' act_as_follower gem button implementation

I have implementet the acts_as_follower gem (https://github.com/tcocca/acts_as_follower) but have trouple implementing the follow/unfollow functionality in the view. In the console the following ...
0
votes
1answer
13 views

Regular Expression in Atom Text Editor, exclude string “abc” from beginning of string

I have some code as follows: data[:value] = some_val data[:value_two] = someval2 data[:total_value_three] = someval3 I want to replace all code where total is not included, I want the following ...
1
vote
1answer
10 views

Why can I run create on model with undefined polymorphic association in seeds.rb but not in my controller?

I run the following code in my seeds.rbfile. page = BlocksEditor::Page.create(name: "A Page") When I try to run the same code in a controller. I get a validation error saying that the polymorphic ...
2
votes
1answer
25 views

How can I DRY out this Ruby code in my Tic-Tac-Toe game? (Uses a 1.times block!)

I'm wondering if anybody can help me out with this...I'm sure it's one of those forehead-slapping things...but I can't figure out how to DRY this bit up. I'm making a Tic-Tac-Toe program as a ...
0
votes
1answer
12 views

Error - RSpec - expect method is escaping '\n'

I would like to assert this expectation: contas_csv = transacoes_decorator.converter_contas_para_csv expect(contas_csv).to eq('345,30000\n350,19500\n355,20000\n360,-31000\n') I got this error: ...
0
votes
1answer
29 views

How to get the latest day from a list of dates in ruby

Im looking a clean way to get an array of dates and considering that the whole range in one year. days = [1, 31] dates = [] (start_date..end_date).each do |date| dates << if days.include? ...
-1
votes
0answers
10 views

ruby (extrat the ip address last login and sort them)

First I have a file derived from the last command in Linux. But I have hard time to figure out how to extract and sort every IP address and last command for each user. This actually how the ...
0
votes
1answer
35 views

Stack level too deep, even though recursive call is at end of function?

I am following the advice of the answer here, and have confirmed that :tailcall_optimization=>true and :trace_instruction=>false, but I'm still getting: SystemStackError: stack level too deep ....
1
vote
1answer
13 views

how to know ruby bit in ubuntu 14.04

I am in the need to install Oracle Instant Client Packages o ubuntu OS from this link. When I was below, I found there was note as- Note: use 32-bit packages for 32-bit ruby even though the OS is ...
0
votes
0answers
7 views

actioncable does not work after deploy to heroku

I have just completed the action cable tutorial from the learn enough site. Everything is working fine in development but after deploying to heroku the action cables don't work. I have made sure to do ...
0
votes
1answer
8 views

Refactoring Ruby scrape code (with different attributes)

I'm scraping ~10 websites for the same information, and currently have a script for each one of them that works on its own. These scripts all have the same base (iterate over available pages, scrape ...
0
votes
0answers
5 views

Reform gem: Associated records

I have the following associations: class Application < ActiveRecord::Base belongs_to :applicant end class Applicant < User has_many :applications, dependent: :destroy has_many :...
0
votes
1answer
16 views

Yet another forbidden attributes error - cannot find where I am going wrong with this

New to Rails. Self teaching. The title pretty much sums it up I'm building your basic blog app and am working on a comment functionality. Three different tables being used: User, Post, Comment with ...
0
votes
0answers
3 views

Rails 5 - Rolify - trying to remove an instance of a role from a user

I am trying to learn how to use rolify with my Rails 5 app. I've previously asked lots of questions about Rolify, most recently here but I've not been able to find help. Im struggling to try to ...
1
vote
1answer
13 views

How to populate my database using a JSON in Rails?

I am trying to populate my database by parsing a JSON file and running a ruby script once that would create instances of my models and save them in my database. Example Script: require 'json' ...
0
votes
1answer
15 views

Rails model with nested attributes fails to save but no error message is displayed

I have the following Rails models that communicate through a many-to-many relationship: class Task < ApplicationRecord belongs_to :case has_many :task_actor_roles has_many :task_artifacts ...
1
vote
1answer
25 views

ActionController::UrlGenerationError: No route matches {:action=>“show”, :controller=>“projects”} missing required keys: [:id]

This is the error I'm getting (see below) ProjectsControllerTest#test_should_redirect_create_when_not_logged_in: ActionController::UrlGenerationError: No route matches{:action=>"show", :controller=...
1
vote
2answers
24 views

When is a block or object that is passed to Hash.new created or run?

I'm going through ruby koans and I am having a little trouble understanding when this code will be run: hash = Hash.new {|hash, key| hash[key] = [] } If there are no values in the hash, when does ...
-2
votes
0answers
18 views

Incomplete response received from application

I want to begin with ruby as language for web application programming. So I used the vagrant box Rubick to start with. But when I create my hanami project and start the hanami server with bundle I ...
0
votes
1answer
13 views

Ruby - sqlite3, inserting a non ascii string into database

When trying to insert into the database a string such as : "セブンゴースト; 神幻拍挡07;" there is no error but it is read as nil after a select. Exemple : string = "セブンゴースト; 神幻拍挡07;" db = SQLite3::Database.new "...
0
votes
0answers
20 views

What's the best way to deconstruct miscellaneous file formats in ruby?

I have been playing around with the ruby kickscraper library and trying to format the outputs but I'm new to ruby so it's been a bit confusing. Right now I'm trying to reformat the ouput of the ...
2
votes
1answer
33 views

Add string to array nested inside of hash

I have a set of nested hashes. I would like to add the string "Assembly" to the array value associated with [:dennis_ritche][:languages] def adding_to_dennis programmer_hash = { :...
0
votes
1answer
26 views

Improving the readability of Capybara tests

I'm writing a rspec/capybara test that ensures input fields in a form display the correct validations. I'm concerned that my code is not very readable. How can I refactor this to make sure that it's ...
2
votes
1answer
20 views

Confirm a Javascript popup using Nokgiri or Mechanize

I'm running a script that will open up on my localhost, my local server is a vulnerable web app test suite, I'm trying to confirm a XSS popup from a javascript alert. For example: http://127.0.0.1:...
0
votes
3answers
25 views

ActiveRecord select by field comparison

I'm trying to select records where two fields do not have equal values. (where field A does not have the same value as field B). This involves alias_attributes. I would like to be able to use the ...
0
votes
1answer
33 views

Require class with pure Ruby

I'm with the following problem: I'd like to require a 'config/application.rb' file to my index.rb. In my task, I have to use pure Ruby. config/application Dir["app/models/*.rb"].each do |file| ...
0
votes
1answer
30 views

RoR Encryption and Decryption for query string

I've been searching for the past few days about encrypting some data to use on the URL. I basically have 3 strings and i need to encrypt then on a unique token. eg: code: '12345678' email: 'teste@...
1
vote
1answer
14 views

Show Rails Contact Form on main page

I've created a contact form in Rails 4 with this example. But I want to display this contact form on the main/show page of my application. How can I do this? routes.rb. Rails.application.routes.draw ...
0
votes
0answers
8 views

Upgrade mongoid 2.8.1 to 5.1.4 drops performance

this is an open question, I have upgraded recently a very old component, that used to use mongoid 2.8.1 to the newest version, which is 5.1.4. And now I have a really big difference in my components ...
1
vote
2answers
32 views

Remove “ ” from line Ruby [duplicate]

I have a loop which read lines from text file : text = File.open("file.txt").read text.gsub!(/\n\r?/, "\n", ) text.each_line do |line| # do something with line end And in each iteration I ...
0
votes
0answers
24 views

In Ruby on Rails, how can I send multiple update statements to the database using the dafult db connection object?

For performance reasons, I need to issue SQL statements (insertions and updates) directly to the database. I have no problem executing a large insert statement like: @conn = ActiveRecord::Base....
0
votes
0answers
18 views

Rails include Module in Concern Module and not lose instance object reference

I have a concern module named Translatable where I'm trying to include a module called AddressHelper. This is Translatable: module Translatable extend ActiveSupport::Concern include ...
0
votes
1answer
6 views

Nested Attributes Unpermitted wit Embedded Mongoid Document via AJAX

I am trying to submit a document and an embedded document via Ajax call but keep receiving an "Unpermitted parameter" exception. This is my model: class UserForecast ... embeds_many :time_entries ...
0
votes
2answers
32 views

How to merge hash of hashes and set default value if value don't exists

I need to merge values of hash a into out with sort keys in a. a = {"X"=>{12=>1, 11=>4}, "Y"=>{11=>5}, "Z"=>{12=>5}} out = [ {"X": [4, 1]}, {"Y": [5, 0]}, {"Z": [0, 5]}, ]...
-1
votes
0answers
5 views

How to make requests to different google api, using the same access token using ruby gem google-api-client?

How to get request to several different google api, using the existing access token instead of getting new? I get list files from Google Drive with oauth 2.0 authorization and get access token. After ...
0
votes
1answer
23 views

Observer Pattern not working on Ruby

I implemented this example below for use of the Observer Pattern on Ruby. I tried follow this, but didn't work. require "observer" class AAnyClass extend Observable changed notify_observers ...
1
vote
1answer
21 views

How can I fix the loop to return the object passed to `with_object`?

This script continuously takes a user's input until they enter exit, at which point the loop breaks. But why does the loop return nil and not the object passed to with_object? puts "enter lines, type ...
1
vote
1answer
25 views

How to DRY has_attached_file that I write in 5 models

This is my code that I write in 5 different models (same code). has_attached_file :image, s3_region: 'ap-northeast-1', storage: :s3, s3_protocol: :https, s3_credentials: "#{Rails....
0
votes
0answers
6 views

Middleman and environment API variables for development, staging and production builds

Is there a way to manage and use different environment variables in Middleman depending on build settings? Example. Environments of: development, staging, and production In this example, using ...
0
votes
0answers
16 views

Generate marker with rails, ajax and Mapbox

I want my users be able to generate markers on their own maps (on their profile page), when they create a post and enter a country. For now, I'm able to create a post, to choose a country, and save ...