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.
3
votes
2answers
30 views
-3
votes
0answers
28 views
API-only e-commerce Rails app
I'm building an API-only e-commerce Rails app with lots of controllers and an admin panel. I'm thinking on how to namespace/organize my routes and controllers. The best guess I had for now is to try ...
1
vote
2answers
32 views
Creating a percentage complete method for a form
I am a relatively new Rails developer and doctor doing research. In my Rails based research projects I often have questionnaires for which I provide a "% complete" parameter.
Here is an example. You ...
3
votes
1answer
25 views
1
vote
0answers
8 views
Method for adding a product with product attributs to cart
Currently I have an app that have many stores. Each store can have several products. Whom again can have many product attributes assigned to them. For instance a shirt is a product, and size and color ...
0
votes
1answer
47 views
Using as few queries as possible for many table associations
I have a table containing about 30k rows of data and there's several table associations. The problem is that there's like 18 columns, and each column requires 1 db query.
Here's an example of what ...
0
votes
2answers
33 views
Duplication of enum across two models
In my Rails app, I have two classes each with the same enum for status. Code climate is complaining about duplication.
...
2
votes
0answers
26 views
Formatting a long HTML document in a model method
I was asked to make a view which is a mix of HTML & ERB logic available in multiple views. At first this seemed pretty simple. However, some of these views required the output to be plaintext ...
4
votes
1answer
31 views
Three identical AJAX button handlers in three views
In my Rails 4 app I have this event listener:
...
5
votes
2answers
39 views
Refactoring if statement based on a hash key
I have to call Article.to_draft/to_archive/publish method depending on the presence of the ...
3
votes
1answer
38 views
Ruby on rails instance loops
I am trying to use a custom sql query to display different attributes for a product i.e. Size and Price. The query I have when running in console displays as it should
...
6
votes
1answer
58 views
Script to redo a rails migration easily
I need to redo a migration occasionally. The workflow is usually something like this:
find or ls | grep the migration using ...
3
votes
0answers
33 views
Simplify the way a user retrieves scraped information
I'm allowing a user to scrape information from LinkedIn by entering the profile url. However I'm relatively new to creating a service (is that even the correct use case?) and I feel like there's room ...
6
votes
1answer
70 views
Simple authorization module with Rails
I created a simple Authorization module with Rails. I found that there are other authorization systems, such as CanCanCan, but they grant permissions at Model level and, for this particular website I ...
1
vote
1answer
65 views
Simplifying Rails Validation [closed]
I have four fields a, b, c, and d. All of them must be populated if any of them have a value.
So what I want to do is validate that they are all populated, if any of them have a value. I'm trying ...
2
votes
2answers
63 views
Rating the quality of a response based on the number of typos
I have this method which returns the number, but Rubocop said:
Assignment Branch Condition size for rating is too high. [15.84/15]
...
4
votes
2answers
67 views
Rails conditional sorting based on params
The following code sorts the current users bid model items based on a param condition :bid_status. It starts to get messy when checking if the project space (...
3
votes
3answers
96 views
Managing many availability status
I'm a junior who wants to refactor a big method in my code, which has been tested and works:
...
5
votes
2answers
60 views
Rails guestbook with new, index, and Kaminari pagination in the same method
I created a guestbook that on one page displays both the form for a new entry and all of the entries that have been created so far.
I am trying to use Kaminari for pagination for the entries.
Right ...
4
votes
2answers
57 views
Method for gathering the correct data to a specific user
I have quite a lengthy method that I know for sure can be optimized, yet I am not sure how to do it. The method is in my User model, and essentially gets the ...
5
votes
1answer
75 views
Displaying a map of points
I'm working on an HTML text-based game (think like OGame and other browser games of the genre). I've tried worked on a grid controller to display a map of points that you can move around when you have ...
2
votes
1answer
70 views
Managing users and profiles in Rails
I am building a Rails marketplace application using TDD. I would like to get advice on the way in which I have built the User associated ...
2
votes
0answers
50 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
61 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
45 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
71 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
169 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
34 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
158 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
146 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
29 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
33 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
58 views
Filter to convert duration to hours — in controller or model?
I have this before_action method :
...
3
votes
1answer
60 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
47 views
Table rendering helper
I wrote this little helper to render a table, however, working with nested content_tag is messy.
...
4
votes
3answers
82 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
40 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
65 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:
...
1
vote
1answer
39 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
126 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
45 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
132 views
7
votes
1answer
55 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
49 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
89 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
47 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
60 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
75 views