Ruby on Rails is an open-source web development framework written in Ruby. If your question code is written in Ruby on Rails, tag with Ruby as the language tag. Many things are defined by convention, freeing you from having to re-invent things to stay productive.
-1
votes
0answers
15 views
Execution reach to timeout for a large number of records (90K) in Rails
I am using the records to render in view after fetching from database after modification. It is working fine for records up to 5000 but show timeout when try for 90,000 records.
I run individual ...
-1
votes
0answers
18 views
1
vote
0answers
21 views
Service Connector abstraction for Ruby
My Rails apps need to connect to several external services to perform some functions.
Now, I realize that some of the services I need might also be reused outside Rails (like in Capistrano ...
1
vote
0answers
16 views
Best way to scope through embedded document in MongoId
I'm using MongoId in a Rails project. I need to select some products which contain some skus which's an embedded document. The models are respectively Product and <...
2
votes
0answers
15 views
MySQL Workbench RoR Migration Exporter
I created plugin for MySQL Workbench that allows you to export an ER Diagram to RoR migration files. I would like to know if any other developers appreciate it.
export-rails-4-migrations_grt.py
<...
1
vote
1answer
39 views
Skip invalid record and avoid execution break for invalid record
Here is the pseudo code used inside a Rails controller:
...
0
votes
1answer
45 views
Directed Acyclic graph implementation in Ruby on Rails
I have an implementation for a graph node class that I'd like to have function as a directed acyclic graph.
The associations are roughly as follows
...
1
vote
0answers
23 views
Converting ActiveRecord array to JSON
I have two tables, devices and device_properties.
The devices table columns are as follows:
...
0
votes
2answers
48 views
Set ENV variables for Ruby on Rails
I've followed the steps from this video from railscasts for setting ENV variables. This is my configuration
...
3
votes
1answer
61 views
Price rating approach
I'm pretty new to web development and I don't know if my solution is OK according to the best practices, considering performance and clean code.
I have a Merchant model that belongs to a Price model.
...
1
vote
0answers
22 views
Rails JS event system
I'm working on a gem which is relatively simple.
It works by adding data-controller and data-action attributes to the body tag ...
1
vote
1answer
25 views
Rails form helper to display email fields and their validation errors
I have a repeated pattern throughout my app that looks like this:
...
3
votes
1answer
37 views
Where should I put code which calculates stats which will be sent via mail
I want to send mail which will have day to day report. I have setup action mailer like this
...
-4
votes
1answer
36 views
Getting last 5 leave requests for a user - where does the code live [closed]
I have a User model, a user has_many leave_requests, in the user model I have the following code to find the last 5 leave requests:
...
5
votes
1answer
55 views
ActiveAdmin: Hide a whole panel in a smart way
In order to only show relevant information to my users I want to disable the whole panel when all fields inside that panel are empty.
Currently I do this hacky method to get to this result:
...
1
vote
1answer
59 views
Finding mongodb records in batches using mongoid
I want to get records in batches. But mongoid doc says to avoid using skip due as it can be expensive. I wrote this method to iterate through a large number records efficiently.
...
3
votes
1answer
55 views
Imported data from CSV successfully, but slow
Currently I am using the gem activerecord-import to seed more than 55,000 records into my database, and it works fine. However, it takes too much time. I am ...
4
votes
3answers
98 views
Loop through months (1-12)
I currently have this monstrosity:
next_period = (((current_month + tax_period_months)-1) % 12) + 1
I want to get the month that is ...
2
votes
1answer
50 views
List enrolled users & show checkmark if all activities are complete
I'm a beginner with rails working on a rails 4 project to use with my students. Users enroll in lessons; on enrollment, four activities are created for each user (expositions, scrambled, dictations, ...
-1
votes
1answer
43 views
ruby rails 4 initialize and increment instance variables
I have been tinkering with various ways to clean this up and I was wondering if it is more ideal to break this into small methods or way to accomplish this on a single line?
...
2
votes
2answers
69 views
Simple ActiveRecord attributes encryption in Rails 5+
The task at hand was to ensure that certain columns in the database are encrypted in case the database data is stolen. I have a feeling that a lot can be improved here (naming, DSL, encapsulations) ...
2
votes
2answers
88 views
Remove a key from list of hashes
Suppose my milestone is this:
milestones = [ {state: 'unavailable'}, {state: 'arrived'}, {state: 'completed'} ]
I want to remove all the ...
6
votes
2answers
115 views
-1
votes
1answer
33 views
Rails - Events fully booked [closed]
I'm building an events app using Rails. I've installed a code block in my controller to ensure that over-booking doesn't occur once the total number of spaces for the event have been allocated/booked. ...
-1
votes
2answers
45 views
Refactor to avoid cope repetition in loop with condition checking
I have snippet that really look ugly but I don't know how to refactor it:
...
3
votes
2answers
41 views
Ruby Select uniq in one statement
I'm trying to implement some simple logic using rails. Code is working fine but its look uglier to me, could any one help me on refractor or implement in a efficient way.
Context:
Data hash ...
0
votes
1answer
12 views
Creating and sending two kinds of notification messages
I wish to get rid of using switch case with statuses twice in my code. But create_message function will be bigger in the future, so must stay and I don't want to ...
5
votes
3answers
52 views
Marking loans as paid if the payments exceed the loan amount
I have a Rails app where Loan has paid attribute. Loan should be marked as paid if total sum of payments is equal or higher than loan amount_to_pay. Problem is that ...
1
vote
1answer
25 views
Rails query for all questions in tournaments that a user participates in
I'm new to rails and this is the situation I'm in: I have a User model that has many tournaments, a Tournament has many users ...
3
votes
1answer
52 views
Rails UserHelper method
I need help cleaning up this monstrosity. Basically this is a user helper method that generates an array of cumulative user sign ups per week (start of week == Wednesday) starting 2016-06-15.
So ...
1
vote
2answers
57 views
Fetching items from database with “Outstanding” status
I am fetching around more than 300000 items through a query:
...
1
vote
1answer
26 views
Preventing duplicate submission in Rails
I have a Rails app where doctors score patients on diagnosis - their score is the model Baseline. Each Baseline has a user id ...
0
votes
0answers
31 views
Ruby/Rails relationships for fashion categories
The premise of the site is for users to review outfits. So the main model of the site is a repository of outfits.
Fashion changes every season so whether or not ...
3
votes
2answers
45 views
Find out if attributes are identical
I have an array of active record objects. All objects have an attribute result and the value of result can be either 'failed' or 'passed'.
My goal is to find out ...
3
votes
1answer
147 views
Simple object oriented design for an Allergy class
Build a system for entering and displaying the allergies that patients may have.
The allergy will have its own set of symptoms reactions. The allergy will also have a spectrum of severity which ...
3
votes
1answer
57 views
Getting timeslots using a single query
I want to get latest time slots for 2 cases based on doorman true for false based on logged in user.
Cases are:
If doorman is true, the query will be the same
if doorman is false, then I need to ...
1
vote
1answer
49 views
Arabic to Roman Number in Ruby on Rails
I am making a class method in ruby to convert from roman number to Arabic and vice versa. However the loop is run to match each character and again to match with roman mapper. Can I optimize the same? ...
1
vote
1answer
71 views
Conditional merge with Ruby to include a parameter if it hasn't been included
I have the following function, and I have a hunch it can be written more concisely in Ruby.
...
1
vote
1answer
33 views
Ruby object declared as constant [closed]
I have this piece of Ruby code:
HTTPCLIENT = HTTPClient.new
def read_page(url)
HTTPCLIENT.get(url).body
end
The HTTPClient object is being created and ...
6
votes
1answer
41 views
Adding product with attributes
I've been working on refactoring a piece of my code that allows a user to add items to their cart. Each product can also be added with different attributes. Thus if somebody adds the same product, ...
0
votes
0answers
111 views
Ruby thread pool implementation
I'm in the process of adapting the simple thread pool described here to my application. I'm new to concurrency in Ruby, but here is what I have so far:
...
1
vote
1answer
40 views
Method to find posts in children categories
I use the gem act_as_votable to allow users to select categories they like. To get the categories a user likes:
current_user.get_voted(Category)
These ...
2
votes
0answers
19 views
Rails rspec test with mocks/stubs
I'm learning about mocks/stubs/doubles and would like to refactor the following code.
comment is polymorphic and can belong to Post, Product, etc. That's why I ...
5
votes
1answer
180 views
Method to count unread messages
I currently use this method to count unread messages for a user (self here):
...
1
vote
1answer
113 views
Rails Grape API Endpoint optional params validation in update
I have the following rails grape api endpoint in the users resource:
...
2
votes
1answer
58 views
Checking whether a store is open or not by querying over its business hours
I currently have a method that checks if the store is open. It's working nicely, however on the main page I have quite a few stores. Whom again have different locations. Each of these locations again ...
2
votes
1answer
64 views
Rails service for a series of calculations
I'm writing a Rails service in which a series of operations are performed on a record:
...
3
votes
1answer
27 views
3
votes
1answer
47 views
Redirecting to the appropriate URL for some type of notification
I have a polymorphic notification model with action attribute. When user clicks on a notification he/she should be redirected to given page the notification refers to through notifiable.
What is the ...
5
votes
2answers
96 views
Rails controller to manage EC2 instances
I did a small sample application for an Interview. Since I didn't got accepted I would like your opinion on how to improve it.
The aux methods are private.
I have a ...