Questions tagged [ruby-on-rails]

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.

Filter by
Sorted by
Tagged with
0
votes
0answers
27 views

Highly versionable API

Environnement : Rails 6.1.4.1 db : PostgreSQL Hi everyone, I've been working on this for some hours now and want to know how other Rails developpers would react to this type of project structure. ...
1
vote
1answer
17 views

Optimize Tests in Rails6 - Minitest - Factory

I finally got this working but I am concerned I am being 'too' specific in my tests, and also that I am repeating myself a significant amount. I could also combine all of the failures into a single ...
1
vote
1answer
31 views

Rails controller to handle offers and payments for rental housing

I've been adding stuff a bit "blindly" to my controller and currently everything is working as it should, but the controller is gotten very messy. I'm using the gem ...
0
votes
1answer
35 views

User registration API

Would love some feedback on this simple API implementation with Ruby on Rails. Have I used proper naming conventions, readable/manageable code, optimal approaches, etc? As I'm still learning Ruby on ...
0
votes
1answer
26 views

Ruby on Rails - Optimizing a query for a huge database

My application is an insight/statistic application that contains a lot of data. I don't need to do any joins as everything is in one table, and still, when the ...
3
votes
1answer
66 views

Migration in a bioinformatics application that changes a column name and explains the rationale

This very short piece of code is a migration in which a column name is changed to be more descriptive. It is part of a larger bioinformatics application written in RoR that parses the output of ...
1
vote
2answers
35 views

Refactoring Ruby recharge REST API wrapper by using class variables

I am trying to create an API wrapper for recharge (A Shopify subscription service), I am using the HTTParty gem ...
1
vote
2answers
50 views

Querying and rendering an HTML table of ISP performance statistics

I have multiples measurements and I want to render it into tables like this Measurements Operator browsings FTP DL FTP UL Location Event Date Operator avg min max avg min max avg min max Verizon ...
1
vote
1answer
57 views

How to reduce code in hash created using Database and Params in rails

I have wrote following solution for one answer but I want to refactor to make it more simple and readable. I am receiving params ...
1
vote
2answers
76 views

Making the controller clean and readable in (Ruby on Rails)

I have this rails controller which works fine but a lot of business logic is confined in the controller which I believe is not a good practice. ...
1
vote
1answer
54 views

Hooking up active record model with external api in rails app

In my rails application, I have 2 different types of active record user, for e.g. User1 has first_name, email etc and User2 also has these attributes but for user 2 we get the data from an external ...
2
votes
1answer
94 views

How can I make this CSV Importer code better of any code smell?

I wrote this method a few years ago in a Ruby on Rails project, which I think I am not proud of. How can I make this code better to show in-depth professionalism in Ruby? lib/merchant/web_csv_importer....
4
votes
3answers
77 views

App to seed DB, generate CSVs, and export individually or in complex zip files Rails 5

I have an app whose sole purpose is to seed data files and add the data to different CSVs which are zipped and exported by the user. My application controller is filled with lines that all look like ...
2
votes
1answer
191 views

Rails model for aggregate data instead of a real table

I have a rails app with a Project model. Each project has usages which is numeric data. I need to get all the usage for each month and year. I also need to get usage for specific months and years ...
3
votes
1answer
78 views

Presenter pattern implementation

I've recently discovered patterns and decided to implement Presenter pattern inside a pedagogical project. I spent few days playing around with different implementations, reading some Gem's source ...
1
vote
0answers
52 views

Encapsulating Logic to Reuse in Various Contexts

I'm experimenting with ways to reuse code throughout a Rails web app. I'm interested in feedback concerning one such approach! Context A user's request may be scoped to a physical location so that ...
3
votes
1answer
1k views

Rails 6: Attaching Devise current_user.id to form submissions

In my Ruby on Rails 6 app: I have a User class built with Devise, and I scaffolded a List class where each List should belong_to a User. I want Lists created through my app to be automatically ...
1
vote
1answer
54 views

custom hash from group_by hash

I am trying to create a custom hash from a table. User has many transactions. A transaction has a ...
1
vote
1answer
122 views

Rails: create a relationship between comment and user

I'm trying to connect the create of a comment to the current_user. I have a model comment which is a polymorphic association. <...
4
votes
2answers
230 views

Rails Helper to display rating in stars

Using Rails 6. Here's a piece that I wrote just to display number of stars. Obviously I am disgusted by my own code. How would you refactor? ...
3
votes
0answers
75 views

Assigning raffle numbers to users in Rails

Background One part of our Rails app is running a Raffle, usually twice a month, with around 600k entrants each round. Each raffle ticket record will have at least a unique raffle number (consisting ...
3
votes
1answer
214 views

RSpec shared example for CRUD Controllers that might be nested or not

I've been trying to create a shared example to quickly and efficiently test controllers with CRUD operations that might also be nested. I came up with this ...
1
vote
2answers
81 views

Removing duplicate hashes in an array while keeping count of the times the hash was present

I have an array of hashes (price_params['items']) where each item has a key called quantity what I'm trying to do is to clean ...
2
votes
1answer
199 views

Easily interacting with two external apis

Recently I rewrote some methods/functions written by a previous developer mostly due to the fact that the previous implementation overdid the whole 'OO' thing, and used inheritance inappropriately. ...
1
vote
1answer
997 views

better multiple fields validation on ruby/rails

I have a form for an item (Job Item), that has sets of 2 fields based on a type. field and field + _dolar e.g: ...
1
vote
1answer
33 views

Rails initializer to be more clean [closed]

I need a little bit of refactor my initialize method because I think it will make initializer more flexible and readable. ...
2
votes
1answer
176 views

Dynamically combine ActiveRecord Relation results [closed]

This isn't the actual use-case I have but for simplicity, let's say I have an ActiveRecord Animal model in a Rails app. The Animals have a name (string) and ...
0
votes
1answer
290 views

ActiveRecord Query for many to many association

I have two Models in my Rails 6 / PostgreSQL application which have a many to many relation; Car and Driver. The goal is to get ...
2
votes
1answer
112 views

Rails controller method to show an optionally scaled image using MiniMagick

I've got below implementation for my controller and show action which implements MiniMagick gem. I've just wondering is there any better way to write it down? If ...
0
votes
2answers
46 views

Ruby if block refactor from new synthax needed

I have this, I guess, new Ruby syntax in my method but Rubocop are warning me that the second last line is too long. Could you please help me to refactor this method? ...
5
votes
1answer
442 views

Update join table using list of checkboxes in Rails

I have Gig and Singer Active Record models (standard--no customization just yet) with a many-to-many relationship through a ...
2
votes
0answers
101 views

jQuery validation for multi-page registration form

I use JS/JQuery validation for radioboxes, input field etc. Because of AJAX I use one global validation (in a separate file) and 4-5 other files to coverage actions in a relevant registration form ...
1
vote
1answer
54 views

Rails 5.2 callbacks to trigger score recalculation for relationships

I have a model that is in a HABTM relationship with 2 other models: Activity.rb ...
1
vote
1answer
48 views

Enumerating AWS instances in Rails, with error handling

I have created a method, which is raising the same exception in case of any error: ...
3
votes
0answers
36 views

Rails route structure for managing tags

I'm hoping someone could vet my route structure as I've really been struggling with getting something that feels right. Right now I have this nested resource structure: ...
1
vote
1answer
44 views

Re-creating user discounts nightly

I'm calling these two methods on a Worker that is executed every 24 hours at midnight in the background. The code seems to be a little bit difficult to read and I'm not sure if i'm iterating through ...
1
vote
1answer
39 views

Ruby on Rails - Creating many models associated with another one

So I have the following models: ...
0
votes
1answer
32 views

Is there any better / improved / optimise way to approach these input checker? [closed]

Actually I got a form with multiple input (around 39) on which I wish to perform some check and display customs messages based on sets of conditions. I found a way to address my problem but I'm ...
2
votes
1answer
645 views

Rspec test for Rails method to return alphabetically sorted list of tags

I have one model class as listed here: class Post < ActiveRecord::Base has_many :comments def tags comments.map(&:tag).uniq.sort end end and ...
3
votes
2answers
105 views

Keep ABC size down for conditional string concatenation in Ruby

This method takes a comment object and displays it correctly depending on what columns are available. EVENT_TEXT and REASON_TEXT ...
0
votes
1answer
29 views

Searching for combinations of words and numbers

My model called Customer contains a method called generate_fields which creates records based on its return values. ...
1
vote
0answers
118 views

Rails dynamically changing parts of view but using the same method in controller

I have this update method which decides whether to update or recreate(same as update but resets the approval_status and create_date) of the building_approval object. I have the on_progress? method on ...
0
votes
1answer
32 views

Updating one model field based on the associated model's field

I'm wondering if there is any way we can optimize the following code. Scenario is Library's active field should be ...
1
vote
1answer
789 views

Ruby on Rails quiz function

I have created a quiz function in my rails application. Since I want to track responses and make it a server-side application I created a table to record the responses of the questions people answer. ...
2
votes
0answers
72 views

TDD for Ruby On Rails API for group event items

I found myself working in this coding exercise for a work offer. I tried to apply TDD in the process but I didn't get any feedback from the company and I really would like to know what can be improved ...
1
vote
0answers
50 views

A Ruby on Rails controller and JS code to add labels to products, like Gmail's labeling tool

My friend asked me to write a tool that lets users bulk add/edit labels (taxons) to store (spree commerce) products. I came up with this, curious to know if you guys find the code readable/...
1
vote
1answer
51 views

Showing a message when the column is true

I'm making an app using Rails. I have 4 Boolean columns in a table like below, and I want to show a message if that column is true. ...
2
votes
1answer
77 views

Rails thin controller method to change account plan and fire slack message via a service object

I'm a beginner with Rails and am trying to figure out how to keep my controllers clean and thin, and how to work with service objects. I am building an internal tool to manage our SaaS customers, and ...
0
votes
1answer
60 views

Pyramid of doom Grape endpoints

I'm creating an API endpoint to create and delete associations, essential creating and deleting records of a join model. The code below doesn't seem idiomatic or pragmatic at all. What's the best way ...

1
2 3 4 5
12