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
19 views

Make View Code DRY

I've got this code in my View that just list two type of links. Here's an examle output e.g Nounal Pages cleaners/house-cleaners Verbal Pages cleaning/house-cleaning Here's the view code. ...
3
votes
1answer
34 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 ...
1
vote
1answer
35 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 ...
0
votes
0answers
39 views

Ajax Responses and from Rails Controllers into a View [closed]

I've been banging my head against the wall all day and I wonder if I'm barking up the wrong tree with my approach. I have a Controller that Handles my Amazon API search requests and returns an Array ...
0
votes
0answers
29 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
37 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
14 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 ...
-1
votes
0answers
14 views

How to refactor the repeating html tags?

How to refactor the repeating html tags ? Extract with render partial ? But I think it may make it too complex ? ...
5
votes
2answers
70 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
34 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
27 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
28 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
50 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
31 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
15 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
37 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
83 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
45 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
67 views

Bitwise operation to get the weekday name

The function days_name receive a val (string) corresponding to weekdays in hexadecimal. ...
3
votes
2answers
49 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
60 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
73 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
38 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
71 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
75 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
28 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
721 views

Repetitive controller with all methods nearly identical

I have an API with the following code ...
4
votes
1answer
79 views

Better way of checking if the current user already like a post

I have three models which look like this: ...
4
votes
1answer
91 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
67 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 ...
1
vote
0answers
77 views

Written worker using sidekiq for activerecord class

I have two model classes as follows: ...
1
vote
1answer
52 views

Better way of comparing integers

I wrote this class which is comparing some values, how can I improve its performance and maybe make it prettier? You can see at the bottom what type of data it requires, also the array size can reach ...
1
vote
0answers
12 views

Memcache Keys Management Class

I have written below class to manage Memcache keys. My Memcache keys structure are like: ...
0
votes
0answers
28 views

Rewrite Active Record query

How can I improve the readability of the below query, and maybe improve the performance as well? ...
3
votes
3answers
148 views

How would you refactor this case statement?

I've got this code in my ApplicationHelper file: ...
0
votes
1answer
37 views

Store location with some excluded path

This code stores the last know location in the session. The location is not stored if it is one of the exceptions in the if statement. ...
1
vote
1answer
54 views

Cleaning up Rails User Model

this is an app that I started on a while back to get digging into rails. It's grown and is now a functioning app. However, the user model is now over 200 lines long. Would love your opinion on how to ...
5
votes
3answers
124 views

Search for User by first and/or last name, efficiently

I am refactoring a user search that just feels dirty. (Users#search) I need to allow a blank param to search on partial or only a first or last, but don't want to return all the records in the ...
1
vote
1answer
82 views

Various RSpec tests

I've just written my first full batch of RSpec tests and wondered if anyone can comment at a glance on how they might be written easier, more readable, faster etc. There are some pending specs so ...
1
vote
1answer
53 views

Is my code clean enough and standard when processing Ruby on Rails requests using User's time zone?

I have an application in Ruby on Rails (3.2) and I want all the requests to take into account the currently logged in user's time zone. Also, I want to have a helper that will let me display date ...
1
vote
1answer
35 views

Move update_attributes into class and check for non-nil params to update only

There are a number of things wrong with the code here: ...
5
votes
2answers
54 views

Refactor .each where each is redirected into a hash

What would be the best way to refactor this : ...
2
votes
2answers
36 views

Refactor mass assigning from a hash

Here is the piece of my controller action that takes a session[:auth] hash and then assigns the values to the ActiveRecord object represented by ...
1
vote
0answers
15 views

Link in between parenthesis

A common pattern while creating links is adding a help link in between parentheses. Something like this: ...
2
votes
1answer
70 views

Ruby on Rails: refactor big search method

I have big search method in my model that corresponds to search a proper Car. It looks like this: ...
1
vote
0answers
31 views

Displaying blog posts from non-SSL site in SSL site

The Issue I added SSL to a previously static and non-SSL website because some new features will require it. I'm using rails 4.0.5, ruby 1.9.3, and the site is deployed on heroku. [it's at www dot ...
5
votes
1answer
67 views

Reverse-engineering with Filepicker API

I have this script to pull data out of the Filepicker API internal. It's mostly reverse-engineering and the code seems to be ugly to me. How can this be improved? ...
1
vote
0answers
62 views

scraping and saving using Arrays or Objects

I'm using Anemone to Spider a website, I am then using a set of rules specific to that website, to find certain parameters. I feel like it's simple enough, but any attempt I make to save the ...
1
vote
2answers
29 views
0
votes
3answers
123 views

Which syntax is preferred to create a Hash in Ruby on Rails?

I am writing some code in Ruby on Rails to Create an object. I am using Ruby 2.0 and Rails 4.0.3 in my Application. I have a Model called: ...