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.

learn more… | top users | synonyms (1)

-2
votes
0answers
28 views

Vending machine method [closed]

I have a big number of nested iterations in my method: ...
1
vote
0answers
26 views

Decorator pattern for an application

I've created a decorator in my Rails application. However, the initializer has 3 params. Is this generally acceptable in decorator or should I refactor this or try a different pattern? ...
2
votes
0answers
44 views

Saving nested JSON to db, inferring order and record deletion

I've written a method for an API call that updates a store menu. It takes JSON as input, in the following format: ...
-3
votes
1answer
29 views

Fetching shipment statuses for a user [closed]

I think the inherent relations in this query should be self-evident: ...
1
vote
0answers
20 views

Geocoding users' IPs

My Rails app geocodes users' IP when they are created and also when they update their data only if they change their city. The geocoding is slowing down my tests ridiculously. This seems to me to be ...
3
votes
2answers
91 views

Creating a user profile from an omniauth hash

I have this code that creates (or updates) a user from an omniauth hash parameter: ...
2
votes
2answers
69 views

Collecting users' data as an array

I want to collect my users' data as an array: ...
2
votes
1answer
28 views

Reduce the calls to database for validations in rails

I was building a rails web, and used form object to separate the validation logics per form. I had to find_referral_code twice in order to store the user_id of referrer. I wonder how I can improve ...
6
votes
2answers
52 views

Controller for classrooms and students

The actions I'm wondering about are members, add_student, and remove_student. They work ...
2
votes
0answers
46 views

Error handling for Stripe credit card processing

I have a rails application that uses Stripe for credit card processing. Currently several exceptions are being handled anywhere a transaction takes place. The code below is being used currently in 11 ...
1
vote
1answer
39 views

Manager for customer billing and subscriptions in Rails

I'm looking to get rid of a couple dependencies that I have a sneaking suspicion are present in the code that I'm writing. Right now I have a service class that manages my subscriptions for part of ...
2
votes
2answers
38 views

Purchase controller search method

I've been trying to simplify a search method in a project that I've taken over. Is it possible to make the code any cleaner than I already have done? purchase_controller#search (original) ...
0
votes
1answer
17 views

Creation of a Select in a View

I have the following code in a VIEW: ...
4
votes
1answer
46 views

Is my blog controller too “Fat”?

I would like some advice which relates to the "fat model skinny controller" concept in Rails. See my show action in the Micropost controller ...
2
votes
1answer
29 views

Simple Report Data Class

I'm trying to write a class to handle the collecting and calculating of some data. My intention is to have the controller instantiate the Report object, and a very simple view display it. I figured ...
3
votes
1answer
23 views

Using model relationships to find number of responses by a user, to posts of a certain topic type

I have a user, a micropost and a response model. The user has many microposts and has many responses. Microposts have tags using the acts as taggable gem. I need to find the number of responses a ...
1
vote
0answers
31 views

Association count in single query for ActiveRecord

This is a small gem that gives the possibility to include counts of reflections when fetching active record objects. What do you think of the code? Any improvements or other (similar) use cases where ...
0
votes
1answer
39 views

Refactor sign up/in partials

I currently have two partials that I use for signing up and signing in. The code is essentially the same in both except for different images to represent sign up/in via Facebook/Twitter. ...
2
votes
1answer
56 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
40 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
60 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 ...
4
votes
4answers
818 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
67 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 ...
2
votes
0answers
74 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
65 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
46 views

Rspec test reuse code for before_filter and method

Consider following example (controller): ...
4
votes
2answers
62 views
0
votes
1answer
54 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
36 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? ...
2
votes
4answers
64 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
96 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
47 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
44 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 ...
2
votes
3answers
50 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
80 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
68 views

Rails models for Users, Offers, Comments, Documents, and Reviews

I want to simplify my Rails models, current looks like this: ...
4
votes
1answer
105 views

Rails configuration variants for production / development environments

How can duplication be removed from this? ...
4
votes
1answer
62 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
98 views
3
votes
2answers
100 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 ...
1
vote
1answer
104 views

Uploading a file using Net::SFTP

I have a method to upload a file using the Net::SFTP gem: ...
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
149 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
91 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
51 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
70 views

Controller action to process orders and payments

I'm trying to reduce the if statements and simplify this create action. ...