RSpec test for update in another action

I am building an application in Rails 5 that sends user inputs back to a controller called "TestsController." If the params[:answer] matches the "correct_answer" in the controller action, the "test" object, which the TestsCon

DRY for variable Ruby loops

I have a def in ruby like below. Can I do something to make it DRY? like: [e,t,l,te,le,le].each |xxx| do if xxx end Which means do the loops for "Variables", not only "Enumerator". code: def findLogs (obj) if e=obj['E'] e=obj['E']['pkg

Tar a project bundler and send to another system

I have two systems that use the same command line interface written in ruby. One system is using an older version that's incompatible with the scripts we have written. We'd like to use bundler to download all the dependencies for the 2.0 on our own s

Best way to set up a common environment for using Rails

I would like to work on a ruby on rails project with a group of 4 people. If we install rails 4.2.0 how can we ensure that we all share the same environment? Is the only option to have install VM? or is there some other way? I mean what if one user i

method not set on Ruby on Rails 4.2`

Its my first time asking a question here. I know i must be missing something very trivial here but have been unable to sort it out for a while now. I'm new to rails. I have 4 classes, Terminal belongs_to Port, Ports belong to_Country and Countries be

Sort table elements by date

I have the following array. dates = ["6/23/2014", "8/5/2014", "8/19/2014", "6/26/2014", "8/19/2014", "8/19/2014", "7/8/2014", "6/3/2014", "7/30/2014", "7/3/2014

Before creating in the active record

I would like to setup a before_create for all of my modules what i have been trying is: module ActiveRecord module UserMonitor require 'securerandom' before_create :attach_uuid def attach_uuid self.uuid = SecureRandom.uuid.gsub("-","")

Irb Error: undefined 'split' method

I recently opened up irb, and now all of a sudden every time I run irb it gives me this error: load error: /Users/addisonbean/.rvm/rubies/ruby-2.1.2/.irbrc NoMethodError: undefined method `split' for nil:NilClass /Users/addisonbean/.rvm/scripts/irbrc

Export a ruby ​​array to a column in a csv file

In Ruby, I have an array and I'd like to export it into a csv file. However, I want each value of the array to be on a new row, so that the final csv file is one column containing all the array values. What's the most elegant way to do that?Lots of w

Undefined method & ldquo; _path & rdquo; in the rails

I am trying to create a new model and provide user a link to a form to fill the model object. My model (/models/paypal_order): class PaypalOrder < ActiveRecord::Base attr_accessor :card_number, :card_verification end My controller (controllers/paypal

Date ranges overlapping Mongoid and Rails

I'm working on a project that places "bookings" for a particular property. In order to prevent a property from being double booked, I am trying to return a result of properties that are unavailable during a given time frame. In my Booking model,

custom sorting in the ruby ​​table

I have a very specific requirement. There is a three or four liner solution for the same. I need one liner solution. Let's say i have an array like: [["Andorra", "Andorra"], ["United Arab Emirates", "United Arab Emirates

Ruby gem install and how to fix the path

I have a Rails app that I want to upload to AppFog. Installed the command line tool with gem install af successfully but when I want to execute it gives me the error: ~$ af login -bash: af: command not found So I went to my rbenv directory and it's t

View an object with Ruby on Rails

I have some JSON that looks like this. I have it stored and read into an object, @items. [ { { "id": "A", "description": "a_description" }, { "id": "B", "description": "b_descripti

Rails - Add a method to a text field

I'm trying to get the checkSwear method to run on each textfield before it's submitted.. I have basically this: (stripped down) <%= form_for(@profile) do |f| %> <div class="field"> <%= f.label 'I love to ' %>  <%= f.text_fie

Creating an IO ruby ​​object from request.body.read?

I'm using sinatra and transloadit and sending files with xhr using valumns file uploader. I need to create a IO object and fill it with data in request.body.read How can I do that ? thank you.Use StringIO: require 'stringio' StringIO.new(request.body

How would I analyze this XML with Ruby?

Currently, I have an XML document (called Food_Display_Table.xml) with data in a format like this: <Food_Display_Table> <Food_Display_Row> <Food_Code>12350000</Food_Code> <Display_Name>Sour cream dip</Display_Name> ....

Problem with Association on rails 3

View <%= form_for @product, :url => admin_products_path do |f| %> <div> <%= f.label :name %> <%= f.text_field :name %> </div> <div> <%= f.label :description %> <%= f.text_area :description, :rows => 7 %&g

Basic and Form Authentication with Mechanize (Ruby)

I'm trying to log into a site on the company intranet which has a basic authentication popup dialog box and form based authentication. This is the code I'm using (which results in a 401 => Net::HTTPUnauthorized error): require 'rubygems' require 'mec

Sort an array of objects in Ruby by the object attribute?

I have an array of objects in Ruby on Rails. I want to sort the array by an attribute of the object. Is it possible?I recommend using sort_by instead: objects.sort_by {|obj| obj.attribute} Especially if attribute may be calculated.

How to freeze the rake?

I have a rails-app (2.3.2) that I need to install on a server on which rake isn't installed, and on which I haven't got privileges to install gems, so I'd like to freeze the rails gem. However, I can't figure out how to do that. I've put it in the de