ruby-on-rails

How do I populate a table from an Excel Spreadsheet in Rails?

I have a simple 4-column Excel spreadsheet that matches universities to their ID codes for lookup purposes. The file is pretty big (300k). I need to come up with a way to turn this data into a populated table in my Rails app. The catch is that this is a document that is updated now and then, so it can't just be a one-time solution. I...

Allow blank on should validate_uniqueness_of

Using shoulda, any ideas how to allow blank when having this test: should validate_uniqueness_of(:email) Thanks. ...

ActiveRecord :has_many associations and === operator

Can someone explain me this Ruby on Rails puzzle? class Post < ActiveRecord::Base has_many :comments end Post.first.comments.class => Array Array === Post.first.comments => false Array === [ 1 ] => true ...

Non-normalized association with legacy tables in Rails and ActiveRecord

I am building a Rails application accessing a legacy system. The data model contains Customers which can have one or more Subscriptions. A Subscription always belong to one and only one Customer. Though not needed, this association is represented through a join table "subscribes", which do not have an id column: Column | Type...

Activerecord-PostgreSQL Adapter Error

When running "rake db:migrate", i receive the following error: Please install the postgresql adapter: gem install activerecord-postgresql-adapter (dlopen(/Library/Ruby/Gems/1.8/gems/pg-0.9.0/lib/pg_ext.bundle, 9): no suitable image found. Did find: /Library/Ruby/Gems/1.8/gems/pg-0.9.0/lib/pg_ext.bundle: mach-o, but wrong architecture ...

Strange routing

How I can setup my rails app to respond to such urls: http://mydomain.com/white-halogene-lamp http://mydomain.com/children-lamps http://mydomain.com/contact-form The first one should link to my products controller, and show my product with this name The second one should link to my categories controller, and show the category with t...

Ruby on Rails: test db is persisting data. I'm using Cucumber, how do I clear the DB after each scenario?

Title says it all. Preferably, I'd like something to go in this method defined in support/env.rb After do |scenario| end ...

Problem with rake jobs:work.

while i am running rake jobs:work. I am getting this error. ** Invoke jobs:work (first_time) ** Invoke merb_env (first_time) ** Execute merb_env ** Invoke environment (first_time) ** Execute environment rake aborted! uninitialized constant Delayed C:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:443...

Character Sets explained for Dummies!

I don't think i fully understand character sets so i was wondering if anyone would be kind enough to explain it in layman's terms with examples ( for Dummies).I know there is utf8, latin1(ISO 8859-1), ascii ect The more answers the better really. Thank you in advance;-) ...

Update paths of already-created Paperclip attachments

I used to have this buggy Paperclip config: class Photo < ActiveRecord::Base has_attached_file :image, :storage => :s3, :styles => { :medium => "600x600>", :small => "320x320>", :thumb => "100x100#" }, :s3_credentials => "#{RAILS_ROOT}/config/s3.yml", :path => "/:style/:file...

Gem::Install Error

When I try to cleanup my rails versions with sudo gem cleanup rails I get the following error: Cleaning up installed gems... Attempting to uninstall rails-2.3.5 Unable to uninstall rails-2.3.5: Gem::InstallError: cannot uninstall, check `gem list -d rails` Attempting to uninstall rails-1.2.6 Unable to uninstall rails-1.2.6: Gem::Instal...

delayed job problem in rails.

My controller data_files_controller.rb def upload_balances DataFile.load_balances(params) end My model data_file.rb def self.load_balances(params) # Pull the file out of the http request, write it to file system name = params['Filename'] directory = "public/uploads" errors_table_name = "snapshot_errors" upload_file = File.join(...

Conditional path names in Paperclip

I'm using this Paperclip configuration: has_attached_file :image, :storage => :s3, :styles => { :medium => "600x600>", :small => "320x320>", :thumb => "100x100#" }, :s3_credentials => "#{RAILS_ROOT}/config/s3.yml", :path => "/:style/:filename" This gives me nice-looking pat...

Modifying an inherited Rails association

I have a Team class that inherits from a Group class. Both Team and Groups have memberships through the same association. However, I need to run a method after a Team memberships is added but not a Group. I currently have something like this: class Group < ActiveRecord::Base has_many :memberships, :class_name => 'Connec...

Why do I get 'Connection refused - connect(2)' for some models?

I have a rails application running for the past 90 days that suddenly stopped working. Debugging the problem I found that I can read from the DB but not write to it. At least for certain models. There is one model that I can save whereas all others return Connection refused - connect(2) when I attempt to save them. They all used to wo...

Ruby on Rails: Cucumber: how to reset the db after each scenario?

So I am in my test environment now, in the terminial, rake db:test:prepare clears the db... but not when i run it from the code And I have this in features/support/env.rb: Before do task :build_all do [ :debug, :release ].each do |t| $build_type = t Rake::Task["db:test:prepare"].reenable Rake::Task["...

Calculate difference in days ActiveSupport:TimeWithZone in the most "rubyish" style?

I have a feeling someone is going to point me to another question that answers this but I've been searching with no luck over this simple issue. I have a Activerecord with a datetime property. It returns as an ActiveSupport:TimeWithZone. I know I can't compare that to DateTime.now because that doesn't include a zone so I need to use Tim...

Trying to manually recreate a simple generate/scaffolding script

I'm trying to understand Rails from the ground up. I want to learn how to manually create basic show-all/show-single/CRUD functionality in the framework. I currently am working on the display-all functionality, but am stopped by an error when I try to request all items in the Products db Here are the steps I've taken so far: script/g...

Did we really always need to use Ruby/ rails plugin?

I been intersted in ruby and rails lately but what I always encounter in blog/ podcast / book is they will always teach how to use ruby or rails plugin/ ruby instead of writing one. Did we really always need to use plugin, even thing like authorization? Authenticate? Is it really waste time Or hard to write from start? Then if it hard an...

Ruby on Rails wildcard routing such as /foo.htm /foo.php /foo.something

I'm trying to create a routing situation where by default, any URL's such as this: /foo /something /foo.php /somethingelse.xml /something.something.else etc. will all route to one controller, assuming they don't route anywhere else. i can get this to work with the following code in my routes: map.myroute '/:file_or_folder', :con...