ruby-on-rails

How to join across polymorphic tables in one query?

Hi all, I have 2 polymorphic associations through which I need to query. I have a news_article table which has a polymorphic association to teams, players, etc. Those teams, players, etc have a polymorphic association to photos through phototenic. I need to find all articles that have at least one picture that is 500px wide. The Ar...

Mocking/Stubbing an Application Controller method with Mocha (Using Shoulda, Rails 3)

While writing functional tests for a controller, I came across a scenario where I have a before_filter requesting some information from the database that one of my tests requires. I'm using Factory_girl to generate test data but I want to avoid hitting the database when its not explicitly needed. I'd also like to avoid testing my before_...

What's happening when Ruby shows something like this: #<Role:0x11157b630>?

I remember coming across this when first watching some Ruby videos, but I can't find it again. When Ruby shows something like this: #<Role:0x11157b630> ,what is going on? I have three roles (admin/staff/client) and I would like to show one of these, not #<Role:0x11157b630>. Any idea how I could do that? Cheers! ...

Mysql keywords with rails.

My one column name is "usage" and it's conflicting with mysql keywords. To solve out that issue i was passing usage like `usage` with ActiveRecord. That solved my problem. CsvHeader.find(:all,:conditions => ["`usage` = ?",usage])) Right now i am attaching db2 as my database. db2 is not accepting &&. so i have replaced && with and. Ano...

Convert SHA1 back to string

I have a user model on my app, and my password field uses sha1. What i want is to, when i get the sha1 from the DB, to make it a string again. How do i do that? ...

Rails/Passenger: no such file to load -- bundler

I have an application running an old version of Rails (2.2.2) and Passenger that I got up and running using Ruby Enterprise Edition 1.8.7. However, I soon found there were some incompatibilities between older versions of Rails and Ruby 1.8.7, and decided to downgrade to REE 1.8.6. However, now the application fails to start with a LoadEr...

Am i creating a nil object? (undefined method ___ for nil:NilClass) error - ruby on rails

My validations were working for a while, or so I thought. Now I come back to them after a while doing something else and I am getting the error above. I think it means I am creating a nil object with the .new method but I am just lost. It seemed to be a problem with the creation of a new object by the controller because even if I # ou...

How do I use update_attributes with custom setter methods in Rails?

I have a model called Contact with an attribute called phone_number. I have some custom setter methods such as def prefix=(num) self.phone_number[3..5] = num end When I call @contact.update_attributes({:prefix => '510'}), I don't get any errors and @contact gets changed, but the changes don't make their way to the database. I've tr...

How do I test a Formtastic custom input with rspec?

I have a rubygem that defines a custom SemanticFormBuilder class which adds a new Formtastic input type. The code works as expected, but I cannot figure out how to add tests for it. I was thinking I could do something like load up Formtastic, call semantic_form_for, and then ad ann input that uses my custom :as type, but I have no idea w...

Which ruby gems support the Facebook social graph api?

I'm developing a rails application using the facebook api. I've seen a few different ruby gems for integrating with facebook, but the look dated. Is it best to write low-level calls myself? Or is there a decent and current gem available? ...

Rails :HOw to order a table by associated model

I think the problem is trivial.I have two models: User and Betting. User has_many :bettings Betting belongs_to :user I just want to get the users ordered by who made more bettings. Sorry, for my english Thanks in advance Francesco ...

Does Rails 2.3 and Rails 3.0 handle the displaying of arrays differently?

I am going through a video tutorial that was using Rails 2.3, and they did: <%= first_array = ['a', 'b', 'c'] %> When they did that, the output they got was: abc When I am trying to follow along, on my setup (Rails 3.0), I get: ["a", "b", "c"] Is this difference normal or did I do something incorrectly? Thanks. ...

Processing third party payments (using PayPal) while taking a percentage

I know it's possible to sit between a payer and payee using PayPal by just storing payee's PayPal account information. Is it possible to take a percentage of the that transaction and pay it to a different PayPal account. Basically acting as a service fee for using our website? If it helps, I would probably be using Active Merchant f...

How to make a pluggable rails app

Basically, I would like to write a rails 3 app that is embeddable in other rails 3 apps (basically some routes, a controller, and some views, no persisting models) works standalone can be bundled up into a gem and be launched from a command (this one is more a nice to have) From what I have read, rails engines would totally solve my ...

etags and server farm

I gathered from the much famed scaling rails screencasts that at some point when your site gets big and bigger, proxy caching is the way to go. Proxy caching uses etag, among other things and since etags can be more specific and strong validator is perhaps the way to go. However, I also hear that in server farm scenarios the etag is not...

How to Search multiple fields with single text field using metasearch and rails 3?

I've started using the metasearch gem http://metautonomo.us/projects/metasearch/ for a ruby on rails 3 app after seeing it recommended in another stackoverflow post. I would like to have a single text field on a search form that can search in multiple fields rather than have one text field for each. I just havn't been able to figure it ...

.irbrc file not loaded by rails console

Is there a way to get "rails console" to load .irbrc? Or am I supposed to use something else? ...

reverse proxy confusion

Currently I use nginx + passenger for serving my rails app. I have been doing some research on reverse proxies and a few names pop up (squid, varnish and nginx mostly). 1 - Now If I am using nginx as my web server can I stil use it as my reverse proxy? 2 - The general sense is that most sites use nginx for proxying static content and a...

Change order of elements in Rails association collection

If I have a collection of objects through a 'has and belongs to many' association in Rails (e.g. the album 'summer photos' has a collection of photos), how can I arbitrarily change the order of the elements in that collection? For example, there is a default index that would yield @album.images[0] or .first. how would I go about ch...

Rails 3 routes - how can I automatically map each action (with exceptions)?

I am a relative beginner at Rails 3 routing and it has now caused me enough pain that I want to figure out the real solution. A couple of details: I have some semi-restful controllers that contain some methods outside the standard seven new, create, edit, update, destroy, etc. Generally, I want my routes page to map everything to 'con...