Tagged Questions

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
vote
0answers
6 views

RSpec integration tests for a simple Rails API

The Model is simple. A Player class with three attributes: first_name, last_name, and team_id. I'm just trying to get a handle on TDD for what will expand into a much more robust API. Below is my ...
3
votes
0answers
65 views

Rails partial inheritance hack

I have a STI table and want to be able to render a collection using render @collection with every elements of the collection using their own partial or, if they don't have one, the parent ...
1
vote
2answers
53 views

Multiple ORs in if-else

How do I refactor this in Rails? if formatted_address.blank? || country.blank? || lat.blank? || lng.blank? ... end If I have 10 attributes to check if blank, I don't wanna retype .blank? 10 ...
0
votes
0answers
18 views

normalization fails with first_or_create [closed]

This question is apparently trivial, but I am a newbie in Rails and I can't figure out where I get it wrong. I am populating associated models from an old spreadsheet. Below is a rake import task ...
3
votes
1answer
45 views

Protecting certain model attributes from being exposed in an API

There can be a business or security requirement that certain fields on a model should never be exposed in an API. One approach to this is to tell the developers not to ever put the field in the API ...
2
votes
0answers
29 views

Organizing models/domain logic in a Rails app using Domain Driven Design [closed]

I've been reading up on Domain Driven Design (DDD) and am a little lost on the implementation details. I like the philosophies that I've learned so far. For example, I've seen a lot of code make its ...
1
vote
0answers
29 views

Rails 3 - improving efficiency of unread post functionality - eliminating duplicate queries

I am working on a Rails 3.2.6 app for a friend which has implements some message board functionality. Users can post messages into a categories. Each user also has a list of other users they have ...
4
votes
1answer
124 views

scopes chaining by OR

How can i DRY these scopes? scope :reputed, -> { joins{reputations.outer}. where{['coalesce(rs_reputations.value, 0) > ? OR purchases.force_active = ?', LOWEST_VOTE, true]} } ...
1
vote
1answer
58 views

What is your opinion to my cucumber feature for arrangement of record to show top 100 [closed]

What are the scenarios that you can think of? Is the scenario I wrote fulfill the feature? Feature: top article listing In order to figure out which article should go to the cover story as a Chief ...
3
votes
1answer
74 views

Rails: Cleaning parameters before passing them to a model

I'm writing an API and want to be able to pass in the attributes of a model without prefixing them with the name of the model. I wrote this little extension to ActiveRecord in order to make it happen: ...
0
votes
1answer
51 views

How to create associative hashs in Ruby (on Rails) dynamicly [closed]

I am developing a webapp with Ruby on Rails to expand the features of mite (online time-tracking app) with the help of the offical mite API. Unfortuanaly, the API can't return all projects by a ...
2
votes
2answers
57 views

How render from a FormBuilder

I'm starting Rails and Ruby for a short time. But I try to make it the cleanest way I can. So, in an attempt to clean my view I try to custom my FormBuilder. Like this : # ...
0
votes
0answers
46 views

Rails has_many using finder method in place of :finder_sql

We have a multi-table association in a model, which is something around the lines of: class MyClass < ActiveRecord::Base def related_instances some_class.all( :select => 'DISTINCT ...
2
votes
3answers
124 views

Trying to improve another if/else statement

Is there a way to optimize the following if/else statement? if current_user if current_user.id == @user.id render 'item' else render 'item_friend' end else render 'item' end
1
vote
1answer
55 views

Is the comparing active record result with array of object in rspec test flexible?

Is the test flexible? describe "self.sort" do before(:each) do @tee = FactoryGirl.create :author, nickname: "tee jia hen", user: FactoryGirl.create(:user) @jon = FactoryGirl.create ...

1 2 3 4 5 7
15 30 50 per page