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
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
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
I have an array of arr=["abcd"] Q1. Is there a simpler way to split the 'abcd' into arr=["a","b","c","d"] than the following: arr=["abcd"] arr_mod=[] x=0 while x < arr[0].size arr_mod <<
I created an RSpec spec to test if a POST #create action works properly: describe "POST #create" do it "creates a career" do expect { post "/careers/", career: attributes_for(:career) }.to change(Career, :count).by 1 end end
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
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
I have a JSON File which looks like: {"business_id": "vcNAWiLM4dR7D2nwwJ7nCA", "full_address": "4840 E Indian School Rd\nSte 101\nPhoenix, AZ 85018", "hours": {"Tuesday": {"close": &quo
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
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("-","")
I noticed some behaviour of the && operator in combination with string concatenation. nil + "string" # => NoMethodError: undefined method `+' for nil:NilClass a = (nil && nil) # => nil a + "string" # => NoMetho
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
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
I have two arrays: products and services in a partial. They may or may not be paginated so I need to be able to count them wether they are or not. products.total_count works if it's paginated but not if it is isn't. While products.count works if it i
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
Why is command "bundle" not found when using sudo: [ro
[email protected] gitlab]# sudo -u git -H bundle exec rake gitlab:setup RAILS_ENV=production sudo: bundle: command not found [
[email protected] gitlab]# but does exist when not using sudo: [
[email protected]
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,
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
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
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
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
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
I'm newb and I'm sorry because of my dumb question! Please, help me!! I'm working with Rails 3, and this my problem: I have a model name: Photo using gem 'mongoid'. I want to make a permalinks which are readable url instead of unreadable '_id' genera
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> ....
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
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
I have to extract all email addresses from some .txt documents. These emails may have these formats:
[email protected] {a, b, c}@abc.edu some other formats including some @ signs. I choose ruby for my first language to write this program, but i don't know ho
my scripts rely heavily on external programs and scripts. I need to be sure that a program I need to call exists. Manually, I'd check this using 'which' in the commandline. Is there an equivalent to File.exists? for things in $PATH? (yes I guess I co
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.
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