ruby-on-rails

Rails and mysql Cluster disk data

I would like to know whether anybody has deployed a Rails APP + Mysql cluster, saving the data on disk space. I saw a provider as brightbox, doing the same. There is no much info, as well as gems/plugins to work with. ...

Error Logging in Rails

Hi, My team has recently switched to rails, and we're yet to implement an error logging solution for our project. I'd like something like Elmah - http://code.google.com/p/elmah/ - where the errors and details are logged and easily accessible. Are there any suggestions? Thanks! ...

Drawing from an S3 through my photo model gets tangled.

I just migrated my server's photos to an S3. Everything seems to work swimmingly except one little catch. If a user chooses a photo from his existing media, the server returns a 500 error. I assume this is because it might still be either looking for it on my local, OR it doesn't draw from the photo model appropriately : a. From my loc...

How to make Rails Nonblocking?

I have a rails application that occasionally needs to do very slow network calls (that might not ever return) based on a web user hitting a route. If the call is slower than normal (or doesn't return), Rails seems to block, not allowing ANYTHING else to happen (I can't open up another browser and hit a different route, I can't use a dif...

Global before_sending_mail callback in Rails

When a user earns 10 points in my application, he gets an email saying "You just earned 10 points!" If someone earns 10 points per day over a week, I don't mind sending him an email a day – but if someone earns 50 points in a single day, I don't want to send him 5 emails. So I'd like a way to intercept each outgoing email before it get...

Rails 3 Autosave Associated Records For Error

I have the following two models that have has_many and belongs_to relationships. I am trying to sort the ActionItems that belong to an ActionList using the reorder_action_items method. class ActionItem < ActiveRecord::Base belongs_to :action_list default_scope order("sort_order asc, created_at asc") end class ActionList < Active...

Ruby on Rails: Cucumber: is there a way to auto 'show me the page' on a failed test?

Is there a way to automatically show me the page when a test fails, then exit, so that i can fix the test, before continuing.. maybe adding a @skip tag when I don't care if it fails? ...

Sorting a "Find" using methods rather than fields in the database

I have a ticket model which has a method inside called closes_in that calculates the time left from the DB field start_date:date to now. Currently my find query is: @tickets = Ticket.find(:all, :origin => @user.coords, :order => 'distance', I can't just put in closes_in as I get an ...

Ruby on Rails: comparing dates error?

undefined method `<' for nil:NilClass the line the error occurs on @object.expires_at < Date.today so.. how do I compare dates? ...

How do controller actions know which REST operation to perform?

When I'm at /profile/new, for example, and I submit a form to create a profile, Rails knows to perform a POST operation; and when I update that profile from /profile/edit/1, Rails knows to perform a PUT operation... My question is, how does it know to do that? I can't understand how this works past the controller. What exactly is going...

before_filter except override not working

Good afternoon all, I've got a controller running a before filter with an except override. It works fine for all the methods in the controller, save one. I've copied the code for the method in question from another part of my app, just making the changes I need to get it working for this particular area. Here is an example of the con...

Restricting routes to nested resources in Rails

I am trying to create nested resources where the sub-resource doesn't have an existence of its own. e.g., an Address resource which is linked to a Person. My route declaration looks like so: map.resources :persons, :has_many => :addresses This gives me the following routes: person_addresses GET /persons/:person_id/a...

"msvcrt-ruby18.dll was not found" with Ruby

When I try to run even simple rails commands such as: rails -h I get a popup error after a few seconds that says: ruby.exe - Unable To Locate Component This application has failed to start because msvcrt-ruby18.dll was not found. Re-installing the application may fix the problem. I am running: Windows XP (yes I know...

Elegantly escaping errors

I have statements such as @user = User.find(current_user.id) throughout my app. Sometimes a user might enter with a nil variable (such as a new user for whom current_user is nil). I'm sure the dumb way to do this would be to scatter if statements everywhere like... if current_user.exists? @user = User.find(current_user.id) else re...

How to debug devise/warden?

I am trying to setup devise in my rails app. It was working nicely, but now I am not able to login as any of my users I get 'Invalid email or password.' I would like to get more insight why its not authenticating. Is there any devise configuration settings that shed some more light? i.e. what is the query being used to find the user,...

Ruby on Rails: undefined method `call' for nil:NilClass

This is the line it lands on. @object = Object.find(params[:id]) respond_to do |format| if @object.update_attributes(:status=>Object::PUBLISHED, :published_at => Time.now) format.html { redirect_to :action => :publish_detail } format.xml { head :ok } format.json { head :ok } #else # flash[:e...

Eager loading for polymorphic associations

Hi, Not sure this could fall in performance section as well as model/database section, so here goes.... Let's say I have 3 models: Movie { has_one :interest, :as => :resource } Song { has_one :interest, :as => :resource } Story { has_one :interest, :as => :resource } and ... Interest { belongs_to :resource, :polymorphic => true } ...

Conditional string.capitalize

Is there anything out there for a conditional capitalize type function? I want to capitalize a string only if I detect there are a certain percentage of capitals letters. I want to do this because I don't want to run the function on everything, but I do want to run it on strings that I think are written in all caps. Or I guess is ther...

Rails using a join model attribute in a condition for a find

Hey all, I'm using a :has_many, :through association to link two models, User and Place It looks like this - In User: has_many :user_places has_many :places, :through=>:user_places In Place: has_many :user_places has_many :users, :through=>:user_places In User_Place belongs_to :user belongs_to :place belongs_to...

Rails architecture?

I would like to be able to read Rails source code, but I think I can't really do it, because I don't know were to start and how different parts of the code are connected. For example, it's obvious what ActiveModel does and I can read the code, but I don't understand how a Rails app generally gets loaded and when exactly ActiveModel comes...