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
4
votes
3answers
50 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
31 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
55 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
47 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
92 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
40 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
68 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
75 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
54 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
110 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
65 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
196 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
281 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
32 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
69 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
38 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
72 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
44 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
159 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
60 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
31 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
43 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
33 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
41 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
38 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
295 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
78 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
28 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
76 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
30 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
567 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
50 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
48 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
50 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
74 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
56 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 ...
2
votes
2answers
81 views

Modelling football teams and fixtures in Ruby (as compared to SQL)

I am trying to model information around football teams and fixtures. I am using the Premier League fantasy football API for my data. The fixtures API is here, and the team data (along with a lot of ...
3
votes
0answers
85 views

Implementing secure API for use between other internal apps

My team and I are trying to implement a secure API and would appreciate some feedback on the following: If there are areas of improvement in the current code to improve security Recommendations on ...
1
vote
1answer
87 views

Creating an associated object on create/update

My app is setup where there are musical artists and albums have message boards through a has_one polymorphic association. ...
3
votes
0answers
104 views

Retrieving data from the movie database

I am trying to retrieve the series, seasons and episodes from the movie database, however I am pretty new to Ruby on rails and I feel like what I am doing could be improved a lot. I use an ...
3
votes
2answers
148 views

Rails controller for a vocabulary quiz

I'm new to refactoring and I have just refactored an old Rails project that had bloated controller methods. I spun off the bloated methods into its own separate controller following this logic, since ...
2
votes
2answers
54 views

Distinguishing between people who have likes to posts and those who have dislikes

I want to distinguish between people who have likes to posts and those who have dislikes. I want to find a way to improve my code without thinking it is efficient. ...
1
vote
2answers
51 views

URL Routing Application

In a Ruby on Rails application I want to have this routing: for URL www.example.com/reports go to controller documents and action ...
0
votes
2answers
631 views

Ruby on Rails application controller

My application controller keeps growing with small helper methods that I use in both my controller and views, is it okay? or what do you recommend doing? ...
2
votes
0answers
56 views

Counting how many questions in each category are tagged

I have a homepage that shows how many questions are in a certain category which is done through tagging. The functionality is working great, it tells me how many of each there are. However, newrelic'...
4
votes
1answer
155 views

Model Association (Rails 5 API)

I have a Character model that has a CharClass and ClassPerks child. Currently I am ...
0
votes
1answer
135 views

Update the frequency of Sidekiq job

I'm working on a feature which user can set frequency of a job. I am using Sidekiq. My solution is when someone updates the frequency from view, I will delete all old scheduled jobs and create a new ...
2
votes
1answer
1k views

Rails passing in params to association on create method

I am currently using a belongs_to relationship in my Rails application to link a map and a group an object that way I can assign those maps to the user based on the ...

1
2 3 4 5
12