Skip to main content
Share Your Experience: Take the 2024 Developer Survey

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
3 votes
0 answers
27 views

Using Pundit Policy Scopes with Searchkick Results

We are using Searchkick to run our elasticsearch and Pundit to authorize users for specific actions. Below is our module SearchkickScope that does it's best to ...
Romuloux's user avatar
1 vote
1 answer
45 views

Rails session after migrate from PHP (improved)

previusly I make a post for Session Logic for User Verification in Rails Migration. Now the improvement version following advice of the comments is here. The problem was the use of `` for executing in ...
ZAMA's user avatar
  • 35
2 votes
1 answer
73 views

Session Logic for User Verification in Rails Migration

This is a logic to create sessions on RoR 7.1.2 based on the last version of the website which was in vanilla PHP, with the upgrade I have to deal with the users that were already signed up but not ...
ZAMA's user avatar
  • 35
0 votes
0 answers
27 views

Is the pattern I'm using for flash messages (with Turbo/Hotwire) in Rails 7 during a failed create action clean?

Rails 7.1.2 I have a form to create a new Employer that exists on the Employers#index view ...
J.R. Bob Dobbs's user avatar
0 votes
0 answers
18 views

Order Model for a Market Place Ruby on Rails Application

I've created a Marketplace application on ruby on rails and would like to request a review of my code (Order Model) to check if I am in the right track or not...please kindly understand that I am a ...
Panamaniac507's user avatar
2 votes
2 answers
161 views

Ruby SFTP client

I'm on Ruby for three weeks and now I want to learn more. Please review this SFTP client and suggest any necessary changes. ...
user avatar
0 votes
2 answers
242 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
1 vote
0 answers
872 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
52 views

Find items by their properties

Given a map of items to their attributes: ...
Muhammad Ushay's user avatar
2 votes
1 answer
91 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
191 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
4 votes
2 answers
136 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
38 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
113 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
155 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
75 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
240 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
70 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
137 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
203 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
107 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
576 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
112 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
67 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
386 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
430 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
119 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
406 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
214 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
40 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
361 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
735 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
179 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
50 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
965 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
191 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
89 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
64 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
53 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
48 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
1k 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
54 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
166 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

1
2 3 4 5
12