As of May 31, 2023, we have updated our Code of Conduct.

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
0 answers
28 views

Generate an array in Ruby efficiently [closed]

I often have a piece of code that creates an array of elements based on some code block and it goes like this ...
Roman Scherbakov's user avatar
1 vote
2 answers
71 views

Ruby SFTP client

I'm on Ruby for three weeks and now I want to learn more. Can anybody review my code and maybe some one can suggest some changed. ...
Nicholas Winberg's user avatar
0 votes
2 answers
79 views

Ruby on Rails _form implicit partial test with RSpec

I am working with: ruby 3.0.0p0 and Rails 7.0.4 and rspec-rails (6.0.1) I want to test my views. I created Product model with rails scaffolding. I tested all views but I am not sure about _form.html....
codescaptain's user avatar
0 votes
0 answers
288 views

Authentication Using Next Auth + Rails API Server

so I have a Nextjs frontend that is using Next Auth for authentication. This will be using a variety of Oauth providers but for this example and to prove the concept I am just using the ...
Romuloux's user avatar
0 votes
1 answer
43 views

Find items by their properties

Given a map of items to their attributes: ...
Muhammad Ushay's user avatar
2 votes
1 answer
69 views

FizzBuzz solved by neural network

I wrote a very simple AI in C and connected it to the web through Ruby on Rails. It learns the fizzbuzz problem. I'm writing this because I'm back on the job market after 20 years. Of course, ...
Rick's user avatar
  • 23
1 vote
1 answer
94 views

Open a file, with a fallback path if it doesn't exist at one location

I am parsing a file that exists in either app/components/ui or in app/components. If the one in the first dir (...
jeffci's user avatar
  • 248
0 votes
0 answers
353 views

Testing out whether controller response body contains correct data in Rspec Controller specs

Running Rails 7.0.3, Ruby 3.1.2 and rspec-rails 6.0.0rc1 I'm writing out some specs to test for the inclusion of certain data getting sent by my controllers. A ...
Sensanaty's user avatar
  • 185
4 votes
2 answers
112 views

Ruby CLI TicTacToe

I have done Tictactoe game in Ruby. It is my first Object Oriented project in Ruby. I would like to separate all program into a few classes such as Player Board and Game. I want to use more OOP best ...
theplaceofburak's user avatar
1 vote
1 answer
29 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 ...
StartingRails's user avatar
1 vote
1 answer
96 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 ...
Daniel's user avatar
  • 11
1 vote
1 answer
125 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 ...
Jay's user avatar
  • 113
3 votes
1 answer
72 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 ...
Timur Shtatland's user avatar
1 vote
2 answers
178 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 ...
Artyrcheek's user avatar
1 vote
2 answers
67 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 ...
buncis's user avatar
  • 107
1 vote
1 answer
69 views

Group some given users according to their department

I have wrote following solution for one answer but I want to refactor to make it more simple and readable. I am receiving params ...
Kamal Panhwar's user avatar
1 vote
2 answers
122 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. ...
Muhammad Ushay's user avatar
2 votes
1 answer
160 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....
Afolabi Olaoluwa's user avatar
4 votes
3 answers
104 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 ...
atayl16's user avatar
  • 41
2 votes
1 answer
444 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 ...
KNejad's user avatar
  • 171
3 votes
1 answer
92 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 ...
Sumak's user avatar
  • 133
1 vote
0 answers
55 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 ...
jkappers's user avatar
4 votes
1 answer
2k 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 ...
wingmatt's user avatar
1 vote
1 answer
64 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 ...
Aparichith's user avatar
1 vote
1 answer
300 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. <...
Steven Aguilar's user avatar
4 votes
2 answers
374 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? ...
Victor's user avatar
  • 321
3 votes
0 answers
108 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 ...
user63764's user avatar
3 votes
1 answer
361 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 ...
Manos's user avatar
  • 31
1 vote
2 answers
117 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 ...
Sebastian Delgado's user avatar
2 votes
1 answer
201 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. ...
american-ninja-warrior's user avatar
1 vote
1 answer
2k 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: ...
queroga_vqz's user avatar
1 vote
1 answer
37 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. ...
mr_muscle's user avatar
  • 197
2 votes
1 answer
324 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 ...
kaydanzie's user avatar
0 votes
1 answer
627 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 ...
Severin's user avatar
  • 153
2 votes
1 answer
154 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 ...
mr_muscle's user avatar
  • 197
0 votes
2 answers
47 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? ...
mr_muscle's user avatar
  • 197
6 votes
1 answer
809 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 ...
thumbtackthief's user avatar
2 votes
0 answers
173 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 ...
mr_muscle's user avatar
  • 197
1 vote
1 answer
76 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 ...
rmcsharry's user avatar
  • 111
1 vote
1 answer
58 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: ...
Rajkaran Mishra's user avatar
3 votes
0 answers
40 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: ...
Dyl's user avatar
  • 31
1 vote
1 answer
52 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 ...
Sebastian Delgado's user avatar
1 vote
1 answer
42 views

Ruby on Rails - Creating many models associated with another one

So I have the following models: ...
Enrique Moreno Tent's user avatar
0 votes
1 answer
33 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 ...
Matthias's user avatar
2 votes
1 answer
929 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 ...
Dinesh Saini's user avatar
1 vote
2 answers
50 views

Validate if the user is associated with the organization then it must have any valid timezone

...
Dinesh Saini's user avatar
3 votes
2 answers
153 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 ...
willlma's user avatar
  • 273
0 votes
1 answer
32 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. ...
tiagomenegaz's user avatar
1 vote
0 answers
142 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 ...
user196160's user avatar
0 votes
1 answer
41 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 ...
Bibek Sharma's user avatar

1
2 3 4 5
12