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)

0
votes
0answers
22 views

Managing course enrollment

I have written some code to suspend someone's enrollment to a course. A course may have multiple presentations. ...
0
votes
0answers
25 views

Loading Authorization Permissions for Web Application

I've recently started on a decently large project, and I've run into a snag. I need to be able to allow an administrator on the site to define and construct permissions for everyone else on the ...
3
votes
2answers
41 views

Sidekiq worker in Ruby

I have worker code that looks like this: ...
2
votes
2answers
44 views

Move code from controller to model

I'm working a rails application that has a lot of logic in the controller that should be in the model. In the app/controllers/customers_controller.rb#create there ...
-1
votes
0answers
13 views

Converted some raw SQL Queries to ActiveRecord Queries

I have 3 SQL Queries and converted them to ActiveRecord Queries (1) I have some raw sql queries with a couple of inner joins, where and select. ...
3
votes
1answer
37 views

Method that reserves a reservable entity and charges the user

This method works for what I need it to do, but I just don't think it's extremely readable, and could be abstracted into different methods. I have a feeling I'm going against some best practices. ...
2
votes
1answer
47 views

Finding expiring/expired documents

This code is to find expiring/expired documents. It was included in one of the models, say Document. Is this good approach of using constant variables which holds ...
0
votes
0answers
34 views

Saving record payment data to respective tables

I have following action in the controller and am wondering how I can refactor it. ...
3
votes
1answer
38 views

Saving a recommended web article from form in Rails controller

I need criticisms and refactoring advice for my controller code: ...
4
votes
2answers
60 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? ...
3
votes
1answer
71 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
33 views

Fetching shipment statuses for a user [closed]

I think the inherent relations in this query should be self-evident: ...
1
vote
0answers
24 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
109 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
74 views

Collecting users' data as an array

I want to collect my users' data as an array: ...
2
votes
1answer
31 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
63 views

Controller for classrooms and students

The actions I'm wondering about are members, add_student, and remove_student. They work ...
3
votes
1answer
70 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
43 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
39 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
18 views

Creation of a Select in a View

I have the following code in a VIEW: ...
5
votes
1answer
53 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
31 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
35 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
41 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
64 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
1k 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
81 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
110 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
53 views

Rspec test reuse code for before_filter and method

Consider following example (controller): ...
4
votes
2answers
66 views
0
votes
1answer
74 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
40 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
104 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
45 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
95 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
77 views

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

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

Rails configuration variants for production / development environments

How can duplication be removed from this? ...
4
votes
1answer
64 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
99 views
3
votes
2answers
124 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
38 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: ...