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

Custom validation for two fields with same validation but slightly different [on hold]

Here is the scope that causes code smell: ...
-1
votes
0answers
18 views

Ruby on Rails: how to link employees table with devise authentification [closed]

I have a model "Employee", some employees have access to the site via devise authentification. What's the best solution to combine it? I need such functions: 1) Click a button in index view of ...
4
votes
1answer
67 views

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

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

Written worker using sidekiq for activerecord class

I have two model classes as follows: ...
1
vote
1answer
51 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: ...
0
votes
0answers
22 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
127 views

How would you refactor this case statement?

I've got this code in my ApplicationHelper file: ...
0
votes
1answer
31 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
45 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 ...
4
votes
3answers
107 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
55 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
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
30 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
49 views

Refactor .each where each is redirected into a hash

What would be the best way to refactor this : ...
2
votes
2answers
31 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
14 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
58 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
23 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
60 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
45 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
27 views
0
votes
3answers
100 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
72 views

Multiple search filter like the one in freshdesk in rails

I have requirement to apply multiple filters on database. So I am doing this now. I will have multiple conditions in the front end where the user can select the conditions he wants to filter with and ...
1
vote
1answer
45 views

Make an object belong to another object

What I'm doing: @cat = Cat.new(cat_params) @cat.user_id = current_user.id Is there a better way? Once you've created a cat you can do this: ...
1
vote
1answer
29 views

Implementation on AMQP in Ruby

I need comments on the below code: ...
0
votes
0answers
39 views

Creating a spec for confirming user accounts

I've created a spec that how a user confirms his account. It tests the following scenarios: While this code is completely untested (wrote it all in the browser) I don't see why it wouldn't work. ...
2
votes
1answer
89 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 ...
1
vote
1answer
68 views

Creating user accounts as an administrative user

I have a site where user accounts can be created in two ways: by new users (sign up) and by admin users. Since the creation is handled differently in each case, I decided to split the logic into two ...
2
votes
1answer
52 views

Rails preventing ajax view duplication

I have a website where people can write articles and publish/unpublish them. This is done via single button on the page: ...
5
votes
2answers
199 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 ...
1
vote
0answers
48 views

DRY-ing the codes for controller specific javascript assets when using Turbolinks

I started to use Turbolinks gem in my Rails 3 application project. I use //= require_tree . in my application.js When using ...
2
votes
1answer
60 views

Is there a better approach to searching has_and_belongs_to_many relations?

I have Article and Category, with a has_and_belongs_to_many relation between the two. I ...
2
votes
2answers
122 views

Is it SRP still?

I have been trying to get as close to SRP in my code as possible. I have a situation where I need to log leads when interactions happen for a contact. A lead may can be created or updated. There are ...
3
votes
0answers
75 views

Optimizing code for querying multiple related records in Rails

I have an Account, User and Group model. All User and ...
4
votes
2answers
117 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
76 views

Rails refactoring has_many

I have a RoR 4 app, and its model have these associations: ...
3
votes
1answer
279 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 ...
4
votes
2answers
58 views

How can I DRY up these routes?

I have a controller with just a few actions, not the whole 7 RESTful actions situation. Here's what I have so far for routing: ...
3
votes
2answers
141 views

My first model RSpec

This is my first model RSpec test: ...
7
votes
1answer
141 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 ...
0
votes
1answer
33 views

Is it reasonable to have separate controller actions for different user registration paths? Or should I refactor into a fewer number of actions?

I have two registration paths in my app. They are very similar and I am curious if I should simplify 4 associated actions down into two actions that handle the same amount of work. Here are my ...
2
votes
2answers
116 views

Updating tables with bulk of data through CSV

My work is pretty simple. I have to migrate a bulk of data into the specified tables, so that the data does show up at the front-end. The data is provided through the ...
7
votes
2answers
156 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
79 views

Nested trial and error in if-else condition

Using Rails 3.2, I have the following: ...
2
votes
1answer
47 views

Task observer implementation

I need help cleaning up this piece of code. ...