ruby-on-rails

Rolling back a failed rails migration

How do you roll back a failed rails migration? I would expect that rake db:rollback would undo the failed migration, but no, it rolls back the previous migration (the failed migration minus one). And rake db:migrate:down VERSION=myfailedmigration doesn't work either. I've ran into this a few times and it's very frustrating. Here's a simp...

Rails link_to_remote degradation and url_for

Hello I am trying to create a link to destroy and entry in the DB using AJAX but I also want it to function without JavaScript enabled However the following code <%=link_to_remote "Delete", :update => "section_phone", :url => {:controller => "phone_numbers", :action => "destroy", :id => phone_number_display.id }, :href => url_for(:con...

Subclassed model results in NameError in development environment but not in test

This is my Action model: class Action < ActiveRecord::Base end class Fold < Action end class Check < Action end class Call < Action end class Bet < Action end In another model, I have this class Deal < ActiveRecord::Base def Deal.parse_action(action_string) case action_string when "folds": Fold.new() when "checks"...

Understanding Ruby on Rails render times

I am working on an "optimization" on my application and I am trying to understand the output that rails (version 2.2.2) gives at the end of the render. Here is the "old" way: Rendered user/_old_log (25.7ms) Completed in 466ms (View: 195, DB: 8) | 200 OK And the "new" way: Rendered user/_new_log (48.6ms) Completed in 337ms (View: 192...

Only certain users can no longer receive notifications on facebook

Only certain users can no longer receive notifications from my app. I was able to re-produce this with a test account but I dont know how and removing/adding the application doesn't seem to fix the problem. This application is only being used by 4-5 testers and the number of notifications being sent to any given user is very nominal and...

Get ids of elements in a named scope

In ruby on rails, all has_many :widgets methods generate both a object.widgets method and an object.widget_ids method. The latter method is very useful because it bypasses the creation of ActiveRecord objects and runs a much faster query. The query speed can be improved by using the :select option, but ruby still allocates much more mem...

Finding forums based on a user's permissions

I'm implementing a forum system called rBoard. Code is viewable at http://github.com/radar/rboard. I've reached an impasse with the permissions code that I've been trying to implement and I've decided to turn to the all-knowing, ever-caring Stack Overflow to solve this issue. Relevant information is thusly: Category model class Catego...

'column "id" does not exist' error while trying to associate a Role with a User using rails-authorization

I'm exploring Rails for the first time and trying to add some fairly straightforward role-based security to my test app. Some Googling seemed to indicate rails-authorization is the way to go for this. I followed the README and everything seemed to be going well, but now I'm trying to associate a User with a Role and it fails. Here's the ...

Should I learn PHP or Ruby (on Rails)?

I've done some dabbling in Rails, but I see a lot more jobs wanting/using PHP than I do Rails. I really know neither of these that well (most of my "professional" experience has been hacking around with Classic ASP and some minor dabbling with ASP.NET; I'm comfortable with OOP and C#/VB.NET), but to maximize my job opportunities I'm hig...

SHA1 hashes not matching between my Rails and Cocoa apps

I have a Cocoa app send some data along with a SHA1 hash of that data to a Rails app which verifies that the data and the hash match, but they do not. To be sure I have logged hex versions of the data that is hashed to the console at both the Rails and Cocoa sides, and they match exactly. Here's the Cocoa part: #import <CommonCrypto/C...

Using Rails validation helpers :message but want it without listing the column name in message

Using Rails validation helpers- validates_xxx_of :the_column, :message => "my message" will generate a validation message : *the_column my message* Is there a way to turn-off the inclusion of the column name? (substitute xxx with any validation helper method) ...

Rails STI Controllers

I have a Rails site using STI with the following classes: Pages Homepage < Pages LandingPage < Pages On the front-end all requests get handled by the Pages controller. However, if the object detected is actually an instance of LandingPage, i'd like to have the action on a LandingPages controller get called. (for example, the show me...

Windows Rails-IDE with Remote-File-Support (FTP/sFTP)

I am currently using Aptana RadRails for Ruby on Rails development on my local system. Now I want to work on a Rails-Application that is hosted on my dedicated server, but unfortunatly RadRails does not provide support for Remote File Access (apart from SVN). Is there an IDE for Rails-Applications that gives me the ability to work on an...

ActiveRecord: Can I copy associations?

Is there a way to copy the associations of one model to another... template_model = MyModel.find(id) new_model = template_model.clone new_model.children << template_model.children # I want to *copy* children ...such that I copy the children from the template to the new model? (In fact this code moves children from the template to the ...

Rails "validates_uniqueness_of" Case Sensitivity

Here is the model (I am using SQLLite3): class School < ActiveRecord::Base validates_uniqueness_of :name end For example, after I add "Yale", I cannot add "Yale" but can add "yale." How can I make the validation case insensitive? EDIT: Found it - Active Record Validations ...

Rails join table renders bad sql

UPDATED: to include model relationships I have a many to many join table between Bands and Events (an event has many bands, a band has many events...) I have a main page that lists all events, and a recent page which displays events updated in the past 7 days. Could someone explain why the recent method generates perfect sql with all ...

rails technoweenie / restful-authentication magi-code: Can't find User#register!

I recently installed the technoweenie / restful-authentication plugin (which works as promised), but while going through the *users_controller#created*, I found a reference to a method call on the user model @user.register! Does anyone know where the method is defined? I've pretty much search all of the generated code, and still don'...

Rails Restful-Authentication Plugin fails to login

My clean install of the Restful-Authentication plugin fails with the following message. undefined method `acts_as_state_machine' for #Class:0x46edaf8 Any ideas on how I can resolve this? Note: The *act_as_state_machine* plugin is installed Note: The restful-authentication plugin was installed with the following command script/gen...

Server Push With rails options

I am trying to build a rails application which requires a "server push" functionality ie Comet . I started looking for options I have found three and tried one of them: Juggernaut : I tried it, am not entirely satisfied/comfortable though, has some browser issues with Opera and probably with Flash 10 ( I have tried it for about an hou...

Rails Application Admin Section

I am working on my first Rails application and want to create an admin section. Do I want to keep my views and controllers completely separate (that is, in separate directories) for the admin section and the rest of the site? How can I organize my views/controllers in custom directories (how do I configure the routing)? ...