Ruby on Rails is an open-source web development framework optimized for programmer happiness and maintaining sustainable productivity. Many things are defined by convention, freeing you from having to re-invent things to stay productive.
2
votes
0answers
33 views
Modeling a temperature recording device in Rails
The app will allow users to login and upload a CSV file that contains temperature data from a device. This data will be stored and the user can view all these downloads and select one from a list to ...
2
votes
2answers
45 views
Average days on market calculation
I have the following method which calculates average days on market for a sale type segment:
...
2
votes
1answer
35 views
refactor helper for default state for rails select with enums
I've created a helper method that is essentially used to get the default state of an select:
...
4
votes
1answer
43 views
Using Rails concerns for validation in models
This is my first Rails project. I have read about concerns which are a great tool, but I am confused about how I should redesign my models.
Some models have similar fields, but the validations are ...
4
votes
2answers
91 views
Checking for valid date range in Rails
I am getting a date range from form inputs - the "from" month, day, and year, and the "to" month, day, and year, and then running a report on data for within that date range. I want to first check ...
1
vote
2answers
29 views
Finding the object and the URL associated with a notification
I have a Notification model which inherits from the ActiveRecord class. Each notification is associated with a specific type of action, which is determined by an integer field (...
5
votes
3answers
152 views
Avoid printing attributes of the nil object in Rails
Currently, when I'm wanting to print a value for my class I do the following...
<%= @person.team.name if @person.team.present? %>
This seems really ...
6
votes
1answer
129 views
My first React.js components for a golf app i'm building, how did I do?
So I've recently started to look into react, I feel like I'm understanding it, but I want to make sure I'm doing the best practices before I make too many bad habits.
I'm using the ...
1
vote
1answer
27 views
Is dynamically generating routes from Model enum safe?
I am generating routes and responding to it dynamically by looking at the enum defined in the model. Is this safe and is there more proper method?
...
2
votes
1answer
26 views
Authentication and session creation
My session controller has a method for creating new user session. According to Rubocop's output there is 'Assignment Branch Condition' metric is too high [15.17/15].
...
1
vote
1answer
52 views
Filter to convert duration to hours — in controller or model?
I have this before_action method :
...
3
votes
1answer
34 views
Rails validating API parameters
I wanted to keep my API request logic separate form the controller logic. I therefore make use of a separate model (EmailChecker) that creates an instance of this ...
3
votes
1answer
40 views
Table rendering helper
I wrote this little helper to render a table, however, working with nested content_tag is messy.
...
4
votes
3answers
80 views
Setting locale based on preferences with fallbacks
Consider the following code. Are the multiple assignments to the loc variable a code smell? If so, how can I refactor this?
...
1
vote
0answers
27 views
Copying csv to sql_table
I wrote code that takes csv and export it to sql table. It looks like this:
...
3
votes
0answers
54 views
Multiple many-to-many filter with range using filteriffic
I should say that the code I have works. I feel like there has to be a much more efficient way to do it (especially when I just crashed my server with it).
Relevant schema:
...
0
votes
1answer
38 views
Checking whether users have a role that allows them to index sheets
Is there any DRYer way to write this method ? or is it better to keep it this way for better reader understanding ...
Each role has a list of authorised activities for a specific resource ( in this ...
0
votes
1answer
95 views
What's the best name for a service object in Rails?
One challenge I regularly face is how to name my service objects in Rails.
I like the advice in this blog post on Gourmet Service Objects, a service object performs one action. It holds the business ...
1
vote
1answer
44 views
One hash with params populate two objects
I have a JSON API where a user can update a post and related details to that post. To simplify the process the user just fills in one hash and we don't expose our architecture. What I did here works ...
2
votes
1answer
76 views
7
votes
1answer
53 views
Summing the size/count of associations for multiple records
I'm working on a plain Ruby class within a Rails application.
For the total_leg_count method---is that the best way to go about achieving what I want? I feel like ...
2
votes
1answer
44 views
Skinny model, fat controller in Rails managing user IP addresses
As part of learning Rails framework, I have small app in progress. Basically idea is, user can create IP address, define is it in use, to which server is assigned, which user is it using and role of ...
5
votes
2answers
86 views
LikesControler for a Post
I have this controller that I call via Ajax, where I update the likes of a post.
I have two methods in the user model:
already_like_post?: Where I pass the ...
3
votes
3answers
45 views
Searching purchase records, with or without a vendor criterion
I'm trying to figure out a better way to have one query here. I want to be able to send something to last where statement a wildcard so I can select all vendors. Right now if I don't include that line ...
2
votes
2answers
60 views
Locating existing records
In order to reduce redundancy in my app, I have added the method self.find_or_keep(object) to many of my models in order to find existing records with the same ...
4
votes
2answers
36 views
Multiple DB record creation after a successful operation
I am working on a payment process. Upon a successful payment process, I have to create multiple records. For that, I have made this class:
...
1
vote
2answers
59 views
Managing course enrollment
I have written some code to suspend someone's enrollment to a course. A course may have multiple presentations.
...
3
votes
2answers
60 views
2
votes
2answers
68 views
Move code from controller to model
I'm working a rails application that has a lot of logic in the controller that should be in the model. In the app/controllers/customers_controller.rb#create there ...
3
votes
1answer
41 views
Method that reserves a reservable entity and charges the user
This method works for what I need it to do, but I just don't think it's extremely readable, and could be abstracted into different methods. I have a feeling I'm going against some best practices. ...
2
votes
1answer
57 views
Finding expiring/expired documents
This code is to find expiring/expired documents. It was included in one of the models, say Document.
Is this good approach of using constant variables which holds ...
0
votes
0answers
36 views
Saving record payment data to respective tables
I have following action in the controller and am wondering how I can refactor it.
...
3
votes
1answer
46 views
Saving a recommended web article from form in Rails controller
I need criticisms and refactoring advice for my controller code:
...
4
votes
2answers
85 views
Decorator pattern for an application
I've created a decorator in my Rails application. However, the initializer has 3 params. Is this generally acceptable in decorator or should I refactor this or try a different pattern?
...
3
votes
1answer
83 views
Saving nested JSON to db, inferring order and record deletion
I've written a method for an API call that updates a store menu. It takes JSON as input, in the following format:
...
-3
votes
1answer
35 views
Fetching shipment statuses for a user [closed]
I think the inherent relations in this query should be self-evident:
...
1
vote
0answers
26 views
Geocoding users' IPs
My Rails app geocodes users' IP when they are created and also when they update their data only if they change their city. The geocoding is slowing down my tests ridiculously.
This seems to me to be ...
3
votes
2answers
155 views
Creating a user profile from an omniauth hash
I have this code that creates (or updates) a user from an omniauth hash parameter:
...
2
votes
2answers
76 views
2
votes
1answer
34 views
Reduce the calls to database for validations in rails
I was building a rails web, and used form object to separate the validation logics per form.
I had to find_referral_code twice in order to store the user_id of referrer. I wonder how I can improve ...
6
votes
2answers
90 views
Controller for classrooms and students
The actions I'm wondering about are members, add_student, and remove_student. They work ...
3
votes
1answer
170 views
Error handling for Stripe credit card processing
I have a rails application that uses Stripe for credit card processing. Currently several exceptions are being handled anywhere a transaction takes place. The code below is being used currently in 11 ...
1
vote
1answer
47 views
Manager for customer billing and subscriptions in Rails
I'm looking to get rid of a couple dependencies that I have a sneaking suspicion are present in the code that I'm writing.
Right now I have a service class that manages my subscriptions for part of ...
2
votes
2answers
42 views
Purchase controller search method
I've been trying to simplify a search method in a project that I've taken over. Is it possible to make the code any cleaner than I already have done?
purchase_controller#search (original)
...
0
votes
1answer
18 views
5
votes
1answer
57 views
Is my blog controller too “Fat”?
I would like some advice which relates to the "fat model skinny controller" concept in Rails.
See my show action in the Micropost controller
...
3
votes
1answer
41 views
Simple Report Data Class
I'm trying to write a class to handle the collecting and calculating of some data. My intention is to have the controller instantiate the Report object, and a very simple view display it. I figured ...
3
votes
1answer
27 views
Using model relationships to find number of responses by a user, to posts of a certain topic type
I have a user, a micropost and a response model.
The user has many microposts and has many responses.
Microposts have tags using the acts as taggable gem.
I need to find the number of responses a ...
1
vote
0answers
45 views
Association count in single query for ActiveRecord
This is a small gem that gives the possibility to include counts of reflections when fetching active record objects. What do you think of the code? Any improvements or other (similar) use cases where ...
0
votes
1answer
45 views
Refactor sign up/in partials
I currently have two partials that I use for signing up and signing in. The code is essentially the same in both except for different images to represent sign up/in via Facebook/Twitter.
...