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)

1
vote
1answer
31 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
41 views

Merge two arrays of hashes and map them

I would like to refactor that code. ...
-4
votes
0answers
15 views

How to test for existence of a controller using Rspec [closed]

I'm working on a rails project and I'm new to Rspec. I've got a controller called sessions_controller.rb and all I want to do is test it's existence (not the functionality within that controller). How ...
-2
votes
0answers
23 views

Admin set user as a Mod [closed]

I'm a beginner in Rails and am following Michael Hartl's book. In chapter 9, where he set up an Admin role, and admin can delete users. I want to extend this feature by allowing admin to set users to ...
7
votes
1answer
47 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
29 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
82 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
44 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
57 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
35 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
56 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
52 views

Sidekiq worker in Ruby

I have worker code that looks like this: ...
2
votes
2answers
55 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 ...
3
votes
1answer
39 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
53 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
35 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
43 views

Saving a recommended web article from form in Rails controller

I need criticisms and refactoring advice for my controller code: ...
4
votes
2answers
67 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
72 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
34 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
120 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
75 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
69 views

Controller for classrooms and students

The actions I'm wondering about are members, add_student, and remove_student. They work ...
3
votes
1answer
82 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
44 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
41 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
54 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
35 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
24 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
36 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
43 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 ...
5
votes
4answers
2k 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
90 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
111 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
56 views

Rspec test reuse code for before_filter and method

Consider following example (controller): ...
4
votes
2answers
66 views
1
vote
1answer
87 views

Listing cities in an itinerary

I have a has_many through relationship between my cities and travels that looks like this: ...
2
votes
0answers
42 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
108 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
46 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 ...