Questions tagged [ruby-on-rails]

Ruby on Rails is an open-source web development framework written in Ruby. If your question code is written in Ruby on Rails, tag with Ruby as the language tag. Many things are defined by convention, freeing you from having to re-invent things to stay productive.

Filter by
Sorted by
Tagged with
1
vote
1answer
101 views

activerecord, refactoring the source code

I have three tables ...
2
votes
1answer
203 views

Select records and fill hash

I use ruby 1.8.7. I have method wich select records and fill hash. In my opinion the code is not dry. Could somebody help me to refactor it and make it shorter and more elegant? ...
2
votes
1answer
2k views

Tidying scaffolded Rails controller spec with subject/let

I was just looking at a standard scaffolded Rails controller spec, and tried to get it to use subject or let blocks, and failed miserably ... can subject or let tidy controller specs the same as it ...
3
votes
2answers
1k views

Rails and Redis: how should I handle validation here?

I'm new to rails. I am using Redis instead of something backed w/ ActiveRecord. I need to validate the presence of location, categories, start_date, and end_date. I then need to check that ...
2
votes
2answers
191 views

Sanitize DOM IDs

I needed to create a method that would sanitize DOM IDs based on the HTML 4 criteria (yeah, HTML 5 is a lot looser). Does this make sense? Did I get too cute with making it concise? Am I totally ...
4
votes
1answer
5k views

HTML flash messages

Flash messages are generally composed in the controller. Sometimes we need those flash messages to have links in them (like an undo button). How would you compose such a message? The only sane way I ...
2
votes
2answers
99 views

Should view related methods be included in models?

...
2
votes
2answers
1k views

Rails controller method to accept one rating per IP address via AJAX

My rating controller: ...
1
vote
1answer
3k views

Please help me improve this Rails 3 nested form code

I'm building a rails app which uses a has many through relationship between three models. I have a Recipes model and an Ingredients model. The join table is called rec_items and it contains a few ...
3
votes
1answer
470 views

Activeresource-response gem

I created my first gem for Rails today. https://github.com/Fivell/activeresource-response. This gem adds possibility to access http response object from result of activeresource call. I don't know ...
2
votes
2answers
140 views

Small: Setting locale

I'm new to Rails/Ruby and I would like to get feedback on my little ApplicationController which is able to detect the visitor's language. I'm especially interested ...
4
votes
4answers
2k views

Temperature converter that seems to violate SRP

I've written this class for two purposes (I think only this fact shows that this code violates SRP): convert weight from one unit to another and to represent them accurate or not accurate. So class ...
2
votes
1answer
1k views

Route structure for multiple associations in Rails

I'm doing a site at the moment (first Rails site, learning as I code) and I'm concerned that I'm over complicating the routes. My associations boil down to: ...
1
vote
1answer
255 views

Refactoring custom validator using lots of if's

I have a custom validator that checks the min and max score of different sporting leagues -- e.g., MLB, NBA, NFL, NCAAB, etc. Here's short version of what it looks like: ...
3
votes
2answers
886 views

ActiveRecord model for users who have issues or who assist with issues

I'm running into an issue while playing around with some models in a Rails app. Namely issues of the polymorphic variety. I think I may have solved it, more or less looking for an approval. I have ...
7
votes
1answer
2k views

Dynamic association generation in ActiveRecord

I'm developing a Rails-based web interface/API for a large, vendor-supplied, legacy Oracle database. One of the constraints is that I can't change the schema other than adding views, because it still ...
4
votes
1answer
421 views

Testing Backbone.js

I'm writing a (nearly-)single-page app using Ruby on Rails 3.1 and Backbone.js. Thus, most of my controllers return rootless JSON, courtesy this setting as per the Backbone.js docs: ...
7
votes
0answers
5k views

spec_helper.rb for RSpec, Capybara, FactoryGirl, Spork and Devise

Having been through hundreds of often-conflicting posts on testing with RSpec, Capybara, FactoryGirl, Spork, Guard and Devise without Cucumber, this is the spec_helper which "seems to" work. I'm ...
2
votes
3answers
197 views

How can I improve the isolation for this controller spec?

So I'm doing things the BDD way, writing features first, then moving on to writing specs to add more detail to the mix as I move down the layers. One thing that bothered me, but isn't a big problem, ...
8
votes
3answers
3k views

Linking issues, classifying the relationship as a cause, effect, superset, etc

I first saw this gigantic if and tried to refactor it. Could only end with a endless switch statement. Old code - ...
2
votes
2answers
2k views

Named scopes for instances

I have following relationship schema: ...
7
votes
1answer
407 views

using method missing to reduce the code in ruby

I have a set of Class methods which is : ...
5
votes
4answers
476 views

Fabricate with work dates

I am using code like this everywhere. How can I reduce such this code so that my Ruby code looks a lot cleaner? ...
2
votes
1answer
240 views

ruby code case when not so dry

Ruby code below seems to be not so dry. Can you please help me reduce the code. ...
3
votes
1answer
231 views

How would you ruby-fy this non-AR model class for Ruby on Rails app?

This is a class from my rails application. It is used as non-database model in my RoR application and uses syntax similar to AR design pattern. I wonder is there a way to make this look more like Ruby ...
4
votes
3answers
577 views

Setting bgcolor in Ruby. What's the proper way to do it?

<p style="background-color:#<%= debate.bg_color %>;" > be_color is a method of ...
6
votes
5answers
458 views

Search for products based on criteria

The method must search Products found by criteria and store them in @products. The criteria are as follows: If the user enters ...
5
votes
1answer
4k views

Transactions and locking in Rails 3

I am new to Rails and have a system that needs to process transactions. A user can enter a transaction to which one or more users are tied. These users owe some amount of money to the person making ...
6
votes
1answer
426 views

How and where to define a partial helper module

I want to split my helpers in different modules (and files), but I found some problems which I got around with the following solution: ...
4
votes
1answer
945 views

Cleaning up a multi-model view in Rails3

I'm new to rails and have built a multi-model form. It's working, but some of the code doesn't feel right. The model code is below. I'm using Devise for my user authentication: ...
2
votes
3answers
514 views

Extracting and mangling a parameter from a MySQL configuration file

Is there a better way of doing this? ...
3
votes
3answers
277 views

Counting subscribers with matching ZIP code, interests, and sex

I am trying to cycle through a few of these blocks. They basically narrow down a number of people that fulfill a bunch of attributes. I apologize if this seems really messy, but my database is really ...
6
votes
2answers
415 views

Find associated object if exists, otherwise generate it

I have a simplified model that looks like this: ...
2
votes
2answers
223 views

Setting responses on survey results

The below code feels ugly, how can I make it better? (The part i don't like is the ||=. I also don't know if I like the resulting data structure. (An array of hashes) ...
7
votes
1answer
357 views

Refactor Helper methods

I have two helper methods that return li for view with the li for current view having id as selected. ...
6
votes
1answer
401 views

How to manage different views

I answered a question in stackoverflow but I gave a solution that looks a little dirty to me, I'd like your opinion because I think there is a much smarter way to do it. A guest user should be able ...
9
votes
3answers
2k views

Storing a Ruby app's settings

I have used code which looks a little like this in an app I'm working on: ...
10
votes
2answers
6k views

Return render in Ruby on Rails

Is it bad to do return render? I am doing this to NOT also allow a redirect. ...
6
votes
2answers
726 views

Rails view to list users in a zebra-striped table

...
5
votes
1answer
3k views

Ruby on rails complex select statement...there has to be a better way!

I am building a query that could end up look like this: ...
7
votes
1answer
2k views

Developing a multistep form

I implemented a multistep form with the method described by Ryan Bates in ep217 but I had some weird behavior when refreshing or moving between the steps Acts_as_good_style (old but still good) has a ...
8
votes
1answer
844 views

Avoiding sub-queries in named scopes

I use named scopes all over the place. When I have a named scope that deals with two different tables, I tend to query the second table in a sub-query. That way, if I mix and match with other tables ...
1
vote
4answers
1k views
28
votes
4answers
15k views

Unit-testing a controller in Ruby on Rails

I intend this to be a general question on writing an effective set of test cases for a controller action. I include the following ingredients: Ruby on Rails RSpec: A testing framework. I considered ...
8
votes
1answer
253 views

RubyGem for Enums

A little background first. I've been working on a fairly large Rails application which quickly grew into a breeding ground for "smelly" code. One antipattern we were using a lot was storing objects ...
8
votes
1answer
23k views

Filtering (search) a model with multiple params in hash

This function in my Profile model receive a hash from a search form and should filter the table depending on those values. I guess there is something like a pattern ...
25
votes
5answers
41k views

Use of a regex stored inside a YAML file

I installed settingslogic and in the configuration file I put the regex for the email as follows: ...
7
votes
1answer
1k views

Object cache storage for Rails

I want to have fast cache in which I want to keep all my nomenclature data. I don't want to go with Memcached because I have to do serialize/de-serialize on each object which is slow. So I choose to ...

1
8 9 10 11
12