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
8 views
1
vote
0answers
9 views
Reduce memory use for a property geolocator
So, 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
25 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 ...
0
votes
0answers
14 views
How Can I Restructure These Associations? [on hold]
I have the following set of Models / Associations:
Whilst this makes sense from on object oriented point of view, it introduces a huge distance between, for example; a NewsItem and the Photo.image ...
-2
votes
0answers
10 views
output of puppet facts are not displaying when concatenating the facts [on hold]
I have puppet facts and those facts are displaying individually. But when i am concatenating the facts, the output is not displaying
Here is my code:
l
...
-1
votes
0answers
18 views
Is this rails symmetric encryption code correct?
My RoR application has a feature where a user can use their own password to symmetrically encrypt certain data (over TLS of course). Is the following code correct?
...
-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
2answers
56 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
1answer
19 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
26 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
42 views
1
vote
4answers
46 views
1
vote
1answer
35 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
26 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
32 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
41 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
63 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
63 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
28 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
68 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
37 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?
...
1
vote
1answer
42 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
54 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
75 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
votes
0answers
51 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
84 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
134 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
49 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
28 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
70 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
47 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
19 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
75 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
85 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
67 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
75 views
Bitwise operation to get the weekday name
The function days_name receive a val (string) corresponding to weekdays in hexadecimal.
...
4
votes
2answers
86 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
74 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
96 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
46 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
119 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
79 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
38 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 ...
5
votes
3answers
728 views
4
votes
1answer
81 views
Better way of checking if the current user already like a post
I have three models which look like this:
...
4
votes
1answer
101 views
How could this “complex method” for codeclimate be refactored?
I'm trying to figure out how to refactor some code based on what codeclimate is telling me. So far it seems that any method that is longer than 5 lines or has an ...
1
vote
0answers
71 views
Variable assign expression with multiple expressions
I have three types of variable assign expression with multiple expressions.
It looks ugly, but I'm not sure how to make it more readable.
Type 1
...