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.
1
vote
0answers
34 views
Initializing a new user
I have a method in my rails project that initializes a new user by copying some properties of another. The method should also retain entered parameters if saving the new user is rejected. Rubocop ...
1
vote
1answer
32 views
Empty product model
I don't think I am using MVC concept in Ruby on Rails properly. Model accesses db, controller works on logic and view displays information/data. But in my below code, My Model code is empty. Can ...
3
votes
2answers
54 views
User search controller
I am using the ruby sunspot gem to create a search users function on my site.
It works fine and the users controller for the index page where there is a search form is this
...
2
votes
4answers
91 views
Reduce 'Assignment Branch Condition Size'
I have a method in my Ruby code that sets the default name for my model. Rubocop complains that Assignment Branch Condition Size is too high, 21.24/15. How can I improve this?
...
3
votes
1answer
44 views
Rspec - testing basic functionality - redundant testing?
Being pretty new to testing, I was wondering how many of these tests make sense.
restaurants_controller_spec.rb
...
-1
votes
0answers
18 views
Parsing lines and processing elements
The method process_open_elements decides the fate of process_block elements or runs directly. How can this be refactored to be ...
2
votes
0answers
73 views
Fetching photos and tweets related to selected publications
1) Postgresql
2) User has_many :reports
3) Report belongs_to :user
3) Report belongs_to :publication
4) Publication has_many :reports
4) Publication scope :photos, -> ...
2
votes
3answers
49 views
Controller actions permisson specs
I'm just starting with rails and testing, and not sure what's good way to dry code like this.
...
1
vote
0answers
29 views
4
votes
2answers
61 views
0
votes
0answers
26 views
N+1 query on Ruby on Rails
I have a has_many through relationship between my cities and travels that looks like this:
...
2
votes
0answers
32 views
Sports statistics controller
Is there too much logic in this controller (should I migrate them to the model)? How else can it be refactored?
...
1
vote
0answers
29 views
Create a list of actors based on their movies [closed]
I want to optimize this code for speed. I think there is more faster way.
...
2
votes
4answers
62 views
Return the opposite of two known strings given one
This is probably silly, but I feel like there should be a much more elegant way to do this simple thing. I have two known strings, whichever one is passed in in the parameter I want to return the ...
5
votes
1answer
73 views
Computing overall averages in my web application
I'm a senior Comp. Sci. major working on a senior design project for our faculty. The name of this project is "Gradebook", and it is responsible for allowing instructors to record grades for students ...
3
votes
1answer
55 views
Probability ordering by seller's tariff
I have an instance method (update_priority); it calculates the position of an element, depending on the tariff of its seller.
If the seller is of a level3 tariff, ...
1
vote
1answer
46 views
Find free username based on schema
Hopefully this is not too complicated. I have this code that will generate a username based on the pre-configured schema the admin types in. The fields they can use are:
...
0
votes
2answers
39 views
Testing a simple guard clause in isolation
I’m using decorator objects in a Rails app so that I don’t have to do nil? checks in views. Everything is working nicely and it’s easy to test, but I’m suspicious ...
0
votes
0answers
11 views
2
votes
3answers
48 views
Similar methods to update today's sales, revenue, and profit
Please help me to refactor. I have two models, conversion & statistic.
Methods ...
1
vote
1answer
61 views
Rails integration testing: Should we use strings or named routes in http requests?
When integration testing Rails applications HTTP request helpers can take a string or a named route as the first argument.
I find myself writing:
...
3
votes
0answers
54 views
Rails models for Users, Offers, Comments, Documents, and Reviews
I want to simplify my Rails models, current looks like this:
...
4
votes
1answer
74 views
Rails configuration variants for production / development environments
How can duplication be removed from this?
...
4
votes
1answer
61 views
Strategy to reduce duplicate code in many similar modules
The Situation
I have created some code in the form of modules that each represent a medical questionnaire (I'm calling them Catalogs). Each different questionnaire ...
3
votes
3answers
91 views
3
votes
2answers
70 views
Simple DRY Rails - check if a model belongs to a user
I can clearly see I'm repeating myself, but I don't know how to refractor this without making it really ugly. What I have:
...
2
votes
2answers
37 views
Product matcher refactoring regarding scopes and arrays
I know I have seen this before and I can't remember how to fix it or find where I saw how to fix it:
...
1
vote
1answer
26 views
The block should return the user's current_active_role
def current_active_role
user_roles.each do |r|
if r.is_active_role
return r
end
end
return nil
end
The block above returns ...
0
votes
1answer
53 views
1
vote
0answers
21 views
Joining models to get records
Is there a better way to refactor the join and fetch the required attributes or is there any better option here?
...
3
votes
1answer
100 views
Reading a file in chunks
I currently have the following class that takes a custom file object as an argument and makes a copy of the file locally.
...
2
votes
1answer
38 views
Displaying shows with videos
My method takes a long time to respond, so I'd like to make this method more efficient. I'd also like this method made with joins.
...
4
votes
2answers
78 views
Convert string array to object with true/false flags
Currently a filter parameter of a GET request is used to designate items' categories that will be requested from database and displayed.
The parameter contains ...
0
votes
2answers
47 views
3 features for 1 model = 3 migrations?
I have a model Users that each instance have 3 features. It was alright until I wanted to tell if this instance can do the 1st feature, the 3rd or all.
I did a migration
...
7
votes
1answer
65 views
Controller action to process orders and payments
I'm trying to reduce the if statements and simplify this create action.
...
3
votes
4answers
89 views
Tell, Don't Ask when dealing with displaying model attributes or a null replacement
I have the following model:
...
1
vote
1answer
81 views
Triggering the execution of a job at the end of a timed campaign
I have a task that checks for campaigns that are supposed to be finished by checking the end_at date. If finished, then set the status of the campaign to finished, ...
2
votes
1answer
75 views
DRY-ing up some rspec
I have an rspec spec test that has two sets of the same tests (from 24 Pull Requests). I thought I'd refactor the spec whilst I fixed something else.
Normally I just do a basic ...
4
votes
2answers
56 views
Rendering a selection box for 50 states
I was creating a Rails form where users have to enter their state. I ended up creating a select tag which is really, really ugly.
I'd like to think there's a better way of writing this.
...
3
votes
2answers
80 views
Reservation validation
I got a Reservation model that has reservation_start and reservation_end.
Then I have the ...
1
vote
1answer
60 views
Reduce memory use for a property geolocator
I have to run a script against 40 million objects in my database:
I wrote the script and I want 10 instance of it so I process my objects faster.
The goal is to find all the neighborhood for each ...
0
votes
1answer
176 views
Avoiding Duplicates in a Ruby on Rails Factory Girl Factory with Fake
I have a Factory Girl factory that needs to generate a unique name using Faker. Unfortunately, Factory Girl generates duplicates relatively frequently, which causes intermittent test errors. I ...
-1
votes
1answer
62 views
Feeder for returning an array of items rated by users
Feeder is in charge of returning an array of items rated by users (feed). If there is a watching user (...
0
votes
2answers
83 views
Clean up Rails routes.rb constraints
I'm trying to think of a better way to write these routes in my routes.rb file:
...
1
vote
1answer
72 views
Getting s3 objects with Rails
I have been using aws-sdk gem with Rails, for uploading and downloading objects. I believe it's working fine.
Demo code:
...
4
votes
1answer
209 views
1
vote
4answers
59 views
1
vote
1answer
245 views
Add existing models to a relation using nested attributes
I needed to add existing models to a has-many relation using nested attributes so I overwrote thumbnails_attributes=:
...
2
votes
0answers
33 views
Directions to refactor class for GPS track points
The story started here (Parsing GPS Data) and continued here (Class for median filter)
I've done a lot work and faced new questions.
In short - I made:
Classes for parsers. TrackParser and ...
1
vote
1answer
52 views
Building query for search engine
I'm writing a basic search engine for my website.
It works but I'm really unhappy with the code. I know it can't be improved but I'm lacking some experiences here.
In my params from my search I get:
...