4
votes
1answer
55 views

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

I have three models which look like this: ...
4
votes
1answer
61 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
40 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
28 views

Written worker using sidekiq for activerecord class

I have two model classes as follows: ...
1
vote
1answer
47 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
10 views

Memcache Keys Management Class

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

How would you refactor this case statement?

I've got this code in my ApplicationHelper file: ...
0
votes
1answer
30 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. ...
4
votes
3answers
95 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
52 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
28 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
48 views

Refactor .each where each is redirected into a hash

What would be the best way to refactor this : ...
2
votes
2answers
29 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 ...
2
votes
1answer
56 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
22 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
59 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
42 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
26 views
0
votes
3answers
98 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: ...
1
vote
1answer
28 views

Implementation on AMQP in Ruby

I need comments on the below code: ...
2
votes
1answer
81 views

Complex method - flagged by codeclimate

I am a fairly new (RubyonRails) developer. I desire to improve my coding skills so I used climate to do some review on my code. It gave me a flag for this method that its complex. Is it characterised ...
5
votes
2answers
195 views

Concise nested statements

I really like the ruby ? : syntax for if else statements. However, I'm not sure how to do the following with a nested ...
2
votes
2answers
73 views

Transfer the format of an old string to a new string

First, I've extended the String class to detect uppercase and lowercase characters: ...
0
votes
1answer
40 views

Managing several payment means in my Rails 3.2 app

I'm trying to manage several means of payment in my Rails 3.2 application. Let's say I have 2 means : Credit Cards & Bank Transfers (BIC), working with 2 different payment providers. Those means ...
4
votes
2answers
109 views

Article voting schema

System I'm building has Users and Articles. Users can upvote/downvote Articles and cancel their votes if they want to. Each vote changes article's score. Score equals to sum of all vote values ...
3
votes
2answers
75 views

Rails refactoring has_many

I have a RoR 4 app, and its model have these associations: ...
3
votes
1answer
240 views

My first controller rspec test

I'm just started learning TDD with Rails and RSpec. This is my first test for controller. Just plain RESTful UserController that responds with JSON, so it has no new and edit methods. Please review it ...
7
votes
1answer
140 views

ActiveRecord extension to find next / previous record(s) in one query

I just wrote this gem order_query to find next or previous records relative to the record assuming a (possibly complex) ORDER BY over the records. For example, this ...
7
votes
2answers
150 views

Shorter, better way to write a “query” involving virtual attributes

I have this code in a model for an invoicing app. This virtual attribute current_invoice gets the only non-rescinded invoice associated with a contract. The code ...
6
votes
2answers
77 views

Nested trial and error in if-else condition

Using Rails 3.2, I have the following: ...
6
votes
2answers
104 views

Return input as a partial fraction

I need to write a function that, when given an input (string, float, or int), returns that input as a reduced partial fraction, and it needs to accept a wide array of inputs: ...
4
votes
1answer
319 views

Refactoring multistep form rails

I've implemented just as Ryan Bates suggested in his railscast episode, I've got everything working just right, so here is his approach in the controller : ...
1
vote
1answer
65 views

Refactoring multi if, if possible

I have fully working code, however I'd like to make it nice. I've got these three models: ...
4
votes
3answers
75 views

How to write save block code like this more elegant in Ruby?

I have a class Creator which will execute a block code for a number of times. I'm not sure how to write this in a more elegant way in Ruby. ...
2
votes
1answer
167 views

How can this rails controller test be cleaner refactored?

I tend to write quite explicit tests for my rails controllers exposing APIs with two seperate concerns: meeting the defined API-Response with headers headers and the response itself ensuring the ...
2
votes
1answer
74 views

Render dynamically vertical tabs and set classes depends on if statement

I would like to refactor code below and get rid of if statements for classes from view. ...
0
votes
1answer
197 views

Rails validating with condition block

Rails AR. validate one field, with 4 validators & 2 condition block ...
2
votes
1answer
280 views

Searching over more models rails

I'm trying to implement search over two models. In this example Book and Article. Here are the attributes from both of these : ...
2
votes
1answer
59 views

Using RSpec subject to setup a test

I find myself using subject blocks in my tests to setup example because it is succinct. However is this considered bad form and can it have undesired consequences? ...
0
votes
2answers
72 views

I have a form that involves several models related to each other - is there a cleaner way to write the form?

I have a form that I feel I am overcomplicating because of the relationship between models that are involved. Can you let me know if there's a more elegant solution to what I have? (for reference) ...
2
votes
1answer
91 views

Script for starting a rails app, with some peculiarities

I wanted to write a script, which starts a rails app, and opens it in the browser. I'm trying to implement this in a peculiar way though - I expect two things: the script must wait until the server ...
1
vote
1answer
86 views

How to refactor this importer to handle validation errors?

This is my importer to database from excel file. I would like to handle situations when any error raise. To not breaks whole import when one errors occurs. For example when there is duplicated record ...
1
vote
1answer
61 views

How can I make this CouchDB view code more “correct”?

I have a fairly simple app set up with couchrest_model to capture data pulled in from vendors to couchdb for later searching and archiving. Each document has a show ...
3
votes
2answers
94 views

Performance problem getting student demographics report with ActiveRecord

I have two active records StudentDemographics and StudentWeeklyReport both having has_many ...
5
votes
1answer
107 views

Taking data from a survey

I wrote this Ruby code that takes data from a survey. Seeing as it is my first Ruby project, I know it can be written much better. How could some of this code be written in more idiomatic Ruby? This ...
4
votes
1answer
106 views

Critique my Stack Overflow schema

I'm learning DB design. How would you change the following schema which tries to replicate Stack Overflow's functionality: ...
2
votes
1answer
238 views

Faster way to update/create of a large amount of records?

In our Rails 3.2.13 app (Ruby 2.0.0 + Postgres on Heroku), we are often retreiving a large amount of Order data from an API, and then we need to update or create each order in our database, as well as ...
1
vote
1answer
93 views

Improve a list of if

So a page where I do a search based on a bunch of filters but all of them are optionals. I have my controller here: ...
2
votes
1answer
39 views

“specific case” object that stands for “any object” : is it a good idea ?

I got tired of doing (more or less) this in my rails controllers : ...
4
votes
4answers
100 views

simplify nested conditonals in ruby

I have this authenticate! method where I am trying to retrieve their account based on the subdomain, then find the user. if user is found & their password is ...