Asynchronous API call to update model in Rails

I am making a simple API call to Coinbase's API to get the current buy/sell price of bitcoin. I have a before_save action on my Price model class PriceBtc < ApplicationRecord before_save :save_prices def save_prices = PriceBtc.get_...
more »

2017-12-03 21:12 (1) Answers

PDF editing gem for ruby on rails app

I have a rails app in which user submits a PDF file. I want to edit that PDF file such that i can have line numbers on each line in it. Is there any gem that can help me in doing this task? If there is not any gem for PDF then is there any way or an...
more »

2017-12-03 12:12 (1) Answers

Issues with High Sierra 10.13.1 and Rails?

I've tried installing Rails on a high sierra but keep receiving a "Failed to build gem native extension" error. checking for sys/epoll.h... no ^ This is what I need to be looking at. I'm not sure if this is an issue with the new OS...possibly an i...
more »

2017-12-03 07:12 (1) Answers

Cannot create FactoryGirl's factory for model

I have this situation with legacy project. Suppose I have rails model: rails g model entity name:string In that model there is MAIN_ENTITY constant: class Entity < ActiveRecord::Base MAIN_ENTITY_ID = 1 MAIN_ENTITY = Entity.find(MAIN_ENT...
more »

2017-12-02 13:12 (1) Answers

Gem needs to be required manually

I've created a gem. You can see the full source code here: (in any case, not advertising) However, when I use it in the Rails project # Gemfile gem 'instagram_api_client' it doesn't work untill a manual...
more »

2017-12-01 10:12 (1) Answers

Two Index's on the same row

I have a rails application that exports content from my database in an xls format. I'm looking to create two separate tables without putting them in the same row. Is there anyway to have two index's on the same row? <?xml version="1.0"?> <...
more »

2017-11-30 22:11 (1) Answers

Rails 5 Migration Data Type Issue

I originally developed my rails 5 application using PostgreSQL. I had to change over to a MariaDB after I had done all of my development due to some issues with hosting. I'm trying to put in an update that adds a reference to the admin from my shop...
more »

2017-11-29 16:11 (1) Answers

Unable to run ActiveRecord Migration

I added the gemfile: gem 'activerecord-reputation-system', require: 'reputation_system' to my Rails app in order to add upvote/downvote functionity to a model (I'm following Railscast #364). I installed the gem with no problems. I entered 'rails ...
more »

2017-11-29 13:11 (1) Answers

Ruby: What does binds mean in ActiveRecord gem?

I saw binds as argument in lots of methods, but without any documentation. e.g. Rails Source code def find_by_sql(sql, binds = [], preparable: nil, &block) result_set = connection.select_all(sanitize_sql(sql), "#{name} Load", binds, preparab...
more »

2017-11-29 07:11 (1) Answers

Bundle Install command won't install my gems?

Okay, so I'm very new to Rails, and am just beginning to feel my way around my new Linux operating system as well. I'm currently doing a project for school, and I've followed all of the directions to perfection. For consistency purposes, they want ...
more »

2017-11-29 01:11 (1) Answers

Ruby, query active model dynamically

I have an Order model in my ruby on rails application which has several attributes. I want to query those orders according to parameters given by users such as itemCount, totalPrice and created date. If one of those attributes is given, I mean it's ...
more »

2017-11-28 23:11 (1) Answers

Using the id of subject{create()} in rspec

I'm pretty new to rspec so I'm not sure how to word this properly so I'll give an example of my situation instead: subject(:test) { SomeModel.create(name: name, depend: depend) } let(:name){ "test name" } let(:depend){ create(:depend, //something he...
more »

2017-11-28 08:11 (0) Answers

Querying an Associations::CollectionProxy

If I have a an Associations::CollectionProxy [#ModelName id: 1, name: my_model, #ModelName id: 2, name: my_model2] Would the following make a db request? my_association_collection.find_by(id: 2) Or would it reference the existing result? ...
more »

2017-11-27 21:11 (1) Answers

Ruby aggregate function with model

I have a product model in my ruby on rails application which has name,endorsement and expense attributes. I need to write a query that list all records, but for every record I need to calculate endorsement-expense as income value. That seems to be o...
more »

2017-11-27 18:11 (3) Answers

Draper gem not decorating associated model

I'm following the Draper gem documentation, but the associated model is not being decorated. Here's a snippet of my top-level decorator: module Admin class OrderDecorator < Draper::Decorator delegate_all decorates_finders decorates_...
more »

2017-11-27 16:11 (1) Answers

NoMethodError at before_save callback

I'm getting this error message when submitting a form that creates an object and nested objects: NoMethodError (undefined method `ratio' for nil:NilClass): app/models/sale.rb:57:in `set_total_valuation' app/controllers/api/v1/sales_controller.rb:19...
more »

2017-11-26 22:11 (1) Answers

Save Model errors to flash Rails 5

I want to add hash with model errors to flash and after that redirect. This is the controller: def update current_user.update_attributes(user_params) if current_user.errors.any? flash.keep[:errors] = current_user.errors.messages ...
more »

2017-11-25 18:11 (1) Answers

Installing gems, ruby on rails. Error with json

I'm currently trying to create new app with rails, wanted to install gems in my app directory and got following message: root@ubuntup:/dev/movies-forum# bundle install --path vendor/bundle Don't run Bundler as root. Bundler can ask for sudo if i...
more »

2017-11-25 18:11 (1) Answers

I'm trying to install OpenGraph gem in ruby

I've searched entire web looking for a way to get over this error. But it won't budge. I installed all the libraries and dependencies according to my knowledge even uninstalled ruby and nokogiri and reinstalled again. But this error remains here. ...
more »

2017-11-25 17:11 (1) Answers