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

2
votes
1answer
30 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
30 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
19 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
158 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
64 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
33 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
19 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
41 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
111 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 ...
2
votes
0answers
32 views

Optimizing code for querying multiple related records in Rails

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

Rails refactoring has_many

I have a RoR 4 app, and its model have these associations: ...
3
votes
1answer
169 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
50 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
103 views

My first model RSpec

This is my first model RSpec test: ...
7
votes
1answer
118 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
30 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
85 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
117 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
65 views

Nested trial and error in if-else condition

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

Task observer implementation

I need help cleaning up this piece of code. ...
1
vote
1answer
53 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
94 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
193 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
61 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
70 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. ...
3
votes
1answer
56 views

Horrible case statement for displaying a title

This thing kills me: ...
2
votes
1answer
119 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 ...
3
votes
1answer
71 views

Filtering Index using has_many through relationships

Both Cities and Positions are associated to Jobs through a has_many :through relationship. ...
0
votes
1answer
70 views

Different selects in one form with same name attribute?

I have the following scenario: ...
0
votes
0answers
20 views

Is using Member routes better than creating a Model as a data wrapper?

I have a Rails app that has Users and Classes, both of which have several associated views. I want to keep my routes as RESTful as possible, but also believe creating Models & Controllers as data ...
2
votes
1answer
72 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. ...
2
votes
1answer
43 views

Quickly fixing unmaintainable SCSS code in Rails

I've been working on a website and Rails and am fairly proud of my HTML semantics. However, my CSS code has become enormous in size, which is largely unnecessary for such a small website. How could I ...
0
votes
1answer
125 views

Rails validating with condition block

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

Rails 4.0 api_key implementation

I'll be brief and let the code speak for itself. I need some very harsh, honest, blunt feedback on this code. I am new to Rails - don't hold back. I have a concept of the user having many API keys, ...
2
votes
1answer
169 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 : ...
0
votes
0answers
81 views

Am I doing Angular right?

I'm starting a new project using Rails and AngularJS. Things seem to be going okay, but I'm sure there are certain things I'm doing totally wrong. Here's a snippet from the project. If you just want ...
2
votes
1answer
53 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
71 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
80 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
78 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
58 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
90 views

Performance problem getting student demographics report with ActiveRecord

I have two active records StudentDemographics and StudentWeeklyReport both having has_many ...
0
votes
0answers
80 views

Please review this import method for importing JSON to my Database in Rails

I have this large method to import data to my Rails database, is there any solution to make this code more DRY or a bit shorter? Should I leave it in the match Model or should I put it into it's own ...
2
votes
1answer
57 views

How to refactor logic in the rails forms

In the _form partial I have a rather complicated logic which builds necessary options for input fields: ...
5
votes
1answer
89 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
159 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
83 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
38 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 : ...