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
1answer
32 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
6 views
Memcache Keys Management Class
I have written below class to manage Memcache keys.
My Memcache keys structure are like:
...
0
votes
0answers
16 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
113 views
0
votes
1answer
29 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
35 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
91 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
37 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
50 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 ...
0
votes
0answers
6 views
Is is OK to use a non-primary key as the id in a rails resource? [migrated]
I am getting ready to set up a resource for some new api calls to my rails application.
I am planning on calling the resource devices ie
resources :devices
This ...
1
vote
1answer
23 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
47 views
Refactor .each where each is redirected into a hash
What would be the best way to refactor this :
...
2
votes
2answers
28 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
54 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
57 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
94 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
60 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
37 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
28 views
0
votes
0answers
34 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
77 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
63 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
38 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
191 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
72 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
39 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
36 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
55 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
118 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
68 views
Optimizing code for querying multiple related records in Rails
I have an Account, User and Group model. All User and ...
4
votes
2answers
103 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
74 views
3
votes
1answer
232 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
56 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
125 views
7
votes
1answer
139 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
105 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
147 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
76 views
2
votes
1answer
46 views
1
vote
1answer
78 views
Refactoring method in ApplicationController for Rails App
Here is a method I have in my ApplicationController, but it's "ugly" and needs some cleanup.
...
6
votes
2answers
102 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
299 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
64 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
74 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.
...