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

0
votes
0answers
22 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
44 views

Controller action to process orders and payments

I'm trying to reduce the if statements and simplify this create action. ...
2
votes
3answers
51 views
1
vote
1answer
41 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
49 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
47 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
58 views

Reservation validation

I got a Reservation model that has reservation_start and reservation_end. Then I have the ...
1
vote
0answers
38 views
1
vote
1answer
52 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
50 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
0answers
13 views

Ruby: using .send within a method behaves differently than calling it outside [migrated]

I'm trying to write a little snippet for my Rails app that checks if any tags are present for an object. I have the following code: ...
-1
votes
1answer
61 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
46 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
33 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: ...
3
votes
1answer
63 views
1
vote
4answers
52 views

Defaulting parameters to false

In my rails controllers, I am consistently using this logic: ...
1
vote
1answer
42 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
28 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
39 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: ...
1
vote
1answer
43 views

Parsing GPS data

Recently I sent this code snippet as CV attachment and I got simple answer - this code smells and we employ another developer. I'm new to RoR, so guys can you give me directions to refactor this code ...
-2
votes
1answer
76 views

SQL table: store “status” as integer vs as string [closed]

I've been around a bunch of projects where statuses are stored in the db as a integer, then mapped in the model back to a human readable string: ...
1
vote
1answer
88 views

Testing after_save hooks in Rails 4.2 with MiniTest

I've recently started working on a new application in Rails 4.2.0-beta2. I've been using this as an opportunity to learn more about MiniTest, with a stretch goal of being as strict with myself with ...
1
vote
1answer
31 views

DRY up ivar assignment in Rails new and create controller actions

When creating a new model in Rails, I need to pass a bunch of other models into the view so I can define the correct associations. All I’m really doing here is querying the persistence layer for ...
6
votes
2answers
71 views

How to avoid mounting SQL by concatenating strings?

I found myself mounting a query by concatenating strings. This just seems wrong. Any ideas of how to avoid this kind of situation? I'm using Rails 4, and I don't see how can ...
3
votes
2answers
40 views

Initialise simple_form object inline

Using Rails 4 and a simple form, I'm rendering a couple of forms outside of their native controllers. Rather than scattering initialisers through my controllers, I wondered if it is cleaner to do the ...
0
votes
2answers
63 views

Make multiple conditions in if expression more readable

My logic has to be written in this way, but I think the if expression is too long to read. How can I make it more readable? ...
2
votes
1answer
44 views

View for displaying nounal and verbal pages

I've got this code in my View that just list two type of links. Here's an example output: Nounal Pages cleaners/house-cleaners Verbal Pages cleaning/house-cleaning Here's the view code. How ...
3
votes
1answer
63 views

Searching for something at a location

I'm using Searchkick in a situation where a user might write the location they are searching for, or the thing they are searching for, or both. I've been working on the below code for most of the ...
2
votes
1answer
80 views

Ruby on Rails Method ActiveRecord Query Optimizations

So I have three methods and I'm not sure how to optimize them. I will be working on this and updating this post while I do but basically running these three methods is central to some parts of my ...
1
vote
0answers
66 views

Rails Controller vs Service Object for Application Logic

I have a #change_account action in the accounts controller that verifies if the user has access to the requested account prior to changing the current_account which happens via setting the ...
2
votes
0answers
97 views

DRY my rake import from external database tasks

The application I'm working on runs import tasks each night to get information from an external database and processes and writes it to the local PostgreSQL database. This is so it can be viewed in ...
0
votes
1answer
15 views

Model with many associations produces code complexity

I've refactored this model about 50 times according to codeclimate, trying to get the codesmell down. With all of the associations, I feel like this is as bare bones as I can get it while still ...
5
votes
2answers
185 views

Rails controller method that conditionally filters results

This code for my blog checks to see if tags are in the params hash. If they are, then only posts that are tagged will be paginated. Otherwise, all of the posts are paginated. ...
4
votes
1answer
55 views

Calculation in Concern module using Rails

I wrote the following Concern module. Is it good practice to perform all the calculations in the included scope? How can it be ...
2
votes
1answer
29 views

How should I tell Rails which of these content types to load for a given feed?

I have content management system for an iOS app built with rails. Right now there a are three different types of content. The first two are just strings uploaded into a textfield by the user. One is ...
1
vote
1answer
31 views

Showing a table for open and closed tickets

I have written the following code. It shows a table for open and closed tickets. The code for open tickets is identical with the closed tickets. I was trying to figure out a way to just write one code ...
1
vote
5answers
77 views

Refactor auto-incrementing function in Ruby on Rails

I have a Rails app where we generate calls. Each call has an incident_number which is a unique number based off the following format: 14-00001 (year in 2 digit followed by a dash then a 5 digit ...
1
vote
1answer
57 views

Refactor Coffee Script to fire on page load instead of change

I have a Rails app where I'm trying to select a list of facilities based on what region is selected in a form. So far, I've implemented group_collection_select to do this as well as a bit of ...
1
vote
4answers
20 views

Issue in Ruby Programming Style

I am new to Ruby on Rails. Can some one please help me with this question? How would you modify the following to be consistent with Ruby's style? ...
2
votes
0answers
84 views

Rails app that scrapes forum using Nokogiri gem

I've built a website that scrapes a guitar forum's pages and populates Rails model. I'm using rake task along with heroku scheduler to run background scrapes every hour. On the homepage, the forum ads ...
3
votes
0answers
87 views

Heterogenous tree in the application domain: How do I represent them?

The Domain I have three types of items in my domain: ItemA, ItemB, ItemC. (I can't use their real names.) ItemA has one attribute: thing_id. ItemB has 6 attributes: thing_id, name, description, ...
2
votes
1answer
77 views

Refactor Rails Controller and View to generate less SQL queries

I have a Rails 3.2.14 app where I have a home controller (dashboard). In this controller and view I'm calling multiple instance variables to get different counts based off of scopes I've created in ...
2
votes
1answer
83 views

Bitwise operation to get the weekday name

The function days_name receive a val (string) corresponding to weekdays in hexadecimal. ...
4
votes
2answers
102 views

Rails Carousel View

In my web site, I created a carousel. Just now, I realized that I most likely repeated myself with this code. I would like to learn how to DRY up this code. Here is my view file (.html.erb) format: ...
3
votes
1answer
82 views

Check if a record already exists and update if it exists

I want to check if a record already exists in a database, and return true or false. If it exists, I want to update the ...
5
votes
1answer
104 views

A conditional active record query

I have a conditional active record query that checks to see if a relationship of type X exists (.count > 0) where attribute x ...
1
vote
2answers
48 views

Refactoring complex phone validations

I have a complex phone validation that does the following: First, check if either a home phone, mobile phone or work phone is provided (there will be 3 text fields in form and at least one type of ...
5
votes
2answers
138 views

DRYING up multiple controller action pages in Rails code

One of my rails controllers is horribly overcrowded with a bunch of methods that link to static web pages. Controller ...
2
votes
1answer
80 views

Graceful way to iterate through two arrays and build a master array?

params[:controller_id].each do |cid| params[:zone_number].each do |pzn| zone_ids << Zone.find_by_controller_id_and_number(cid,pzn).id end end I have ...
1
vote
1answer
41 views

Checking if an associated object has failed to save/create

I smell something wrong here, but am not quite sure what the most idiomatic way to solve the problem. I have a controller for (job)listings and it has a method ...