Forbes magazine logo Ranked Best Coding Bootcamps 2023

Questions and Answers

About 153 questions

Refactor following code using map in Ruby

Nice how can i refactor following code using map tag_clouds = {} tag_cloud_names.each do |name| tag_clouds[name] = row.field(row.index(name)).to ...

Asked on 7 February 2018

Why can't I use dot notation to access Ruby Hash Object elements

I have a ruby Hash Object retrieved from the postgresql database. hash = {"foo": bar} puts hash.foo => NoMethodError: undefined method 'foo' for {"foo ...

Asked on 7 February 2018

Is Array.map asynchronous in Ruby?

In JavaScript, Array.map alike methods are asynchronous. How about ruby's Array.map? How can we pass a callback block to the .map alike when it has do ...

Asked on 7 February 2018

How can I test signed or permanent cookies with Rspec?

http://stackoverflow.com/questions/7788929/how-can-i-test-signed-or-permanent-cookies-with-rspec

Asked on 7 February 2018

When trying to start a new rails server, it exits with error saying the port is already in use.

/Users/Username/.rvm/gems/ruby-2.3.1/gems/puma-3.4.0/lib/puma/binder.rb:255:in `initialize': Address already in use - bind(2) for "0.0.0.0" port 3000 ...

Asked on 7 February 2018

[redis-rails] Redis is not a module

After installing redis-rails gem, I get the error message "Redis is not a module" in server logs. If you are using Rails 5, try gem "redis-rails", gi ...

Asked on 7 February 2018

Couldn't find template for digesting inside cache! block

While using a cache! block, I get the error message "Couldn't find template for digesting:" Github issue #1: https://github.com/rails/rails/issues/149 ...

Asked on 7 February 2018

Rails active record model set default order

How do I set default order for rails model when I don't want to use .order when retrieving data? You can do the following class Book < ActiveRecord:: ...

Asked on 7 February 2018

Generate a secret token in Rails

How to generate a secret and secure token in Rails? rake secret

Asked on 7 February 2018

How to COUNT all rows in SQL query while using LIMIT?

You can use the OVER() clause in SQL. PostgreSQL has window functions counting rows before LIMIT is applied. Example: SELECT count(*) OVER() AS total_ ...

Asked on 7 February 2018

Sidekiq does not find sidekiq.pid file on Heroku

In sidekiq.yml, remove the following line: :pidfile: tmp/pids/sidekiq.pid

Asked on 7 February 2018

Rescue ActiveRecord transaction block and also get error messages

begin ActiveRecord::Base.transaction do user.save! # will raise exception if error exists end rescue ActiveRecord::RecordInvalid => exceptio ...

Asked on 7 February 2018

Rescuing Multiple Exception Types in Ruby

Normally, you can rescue a type of exceptions like this begin [] + '' rescue TypeError => e puts "oops: #{e.message}" end And, you can also catch ...

Asked on 7 February 2018

How to test if eager loading is working?

You can use https://github.com/flyerhzm/bullet#run-in-tests and following the instructions under "Run in tests". Bullet gem will raise errors like Bul ...

Asked on 7 February 2018

Expected response to be a <redirect>, but was <200>

How do you test rails controller's redirect_to in Rspec? In Rspec, get :authorize expect(response).to redirect_to('/url/of/your/choice')

Asked on 7 February 2018

How to clear retries attempts in Sidekiq?

$ rails c $ require 'sidekiq/api' $ Sidekiq::RetrySet.new.size # Check the size of the queue by using the size method $ Sidekiq::RetrySet.new.clear # ...

Asked on 7 February 2018

How to test ActionMailer deliver_later with rspec

You can get all enqueue_jobs from ActiveJob ActiveJob::Base.queue_adapter.enqueued_jobs The code above will return all the enqueue jobs, which retur ...

Asked on 7 February 2018

Rails script for generating database

How to write a script for making entries in rails. You can add a task in the lib/tasks folder For example lib/tasks/task_name.rake, task :task_name ...

Asked on 7 February 2018

Index name '...' on table '...' is too long; the limit is 63 characters

You change change the index name to be shorter or equal to 63 characters add_index :table_name, ["column_name_1", "column_name_2", "column_name_3", "c ...

Asked on 7 February 2018

Rails model restrict values from an array of string

You can use class ClassName < ApplicationRecord validates :column_name, inclusion: { in: %w(restrict_text_1, restrict_text_2, restrict_text_3) } e ...

Asked on 7 February 2018

Trusted by

Students and instructors from world-class organizations

Imperial College London
Carnegie Mellon University
City University of Hong Kong
Hack Reactor
Cisco Meraki
University of Oxford
Swift
Bazaarvoice
Waterloo
Uber
AtlanTech
Tumblr
Boston College
Bombardier Aerospace
University of St. Andrews
New York University
Minerva Schools at KGI
Merrill Lynch
Riot Games
JP Morgan
Morgan Stanley
Advanced Placement®
Google
KPMG
The University of Hong Kong
University of Toronto
SCMP
Moat
Zynga
Hello Toby
Deloitte
Goldman Sachs
Yahoo
HSBC
General Assembly
Tesla
McGill University
Microsoft

Join the upcoming Cohort #96

Enroll for December 2nd, 2024