ruby-on-rails

Rails model validators break earlier migrations

I have a sequence of migrations in a rails app which includes the following steps: Create basic version of the 'user' model Create an instance of this model - there needs to be at least one initial user in my system so that you can log in and start using it Update the 'user' model to add a new field / column. Now I'm using "validates...

How (and whether) to populate rails application with initial data

I've got a rails application where users have to log in. Therefore in order for the application to be usable, there must be one initial user in the system for the first person to log in with (they can then create subsequent users). Up to now I've used a migration to add a special user to the database. After asking this question, it se...

Best Practice for Model Design in Ruby on Rails

The RoR tutorials posit one model per table for the ORM to work. My DB schema has some 70 tables divided conceptually into 5 groups of functionality (eg, any given table lives in one and only one functional group, and relations between tables of different groups are minimised.) So: should I design a model per conceptual group, or should...

Importing XML file in Rails app, UTF-16 encoding problem

I'm trying to import an XML file via a web page in a Ruby on Rails application, the code ruby view code is as follows (I've removed HTML layout tags to make reading the code easier) <% form_for( :fmfile, :url => '/fmfiles', :html => { :method => :post, :name => 'Form_Import_DDR', :enctype => 'multipart/form-data' } ) do |f| %> <%= f.fil...

Should rails models be concerned with other models for the sake of skinny controllers?

I read everywhere that business logic belongs in the models and not in controller but where is the limit? I am toying with a personnal accounting application. Account Entry Operation When creating an operation it is only valid if the corresponding entries are created and linked to accounts so that the operation is balanced for exempl...

Rails, Restful Authentication & RSpec - How to test new models that require authentication

I've created a learning application using Bort, which is a base app that includes Restful Authentication and RSpec. I've got it up and running and added a new object that requires users to be logged in before they can do anything(before_filter :login_required in the controller). [edit: I should also mention that the user has_many of th...

Why is RSpec so slow under Rails?

Whenever I run rspec tests for my Rails application it takes forever and a day of overhead before it actually starts running tests. Why is rspec so slow? Is there a way to speed up Rails' initial load or single out the part of my Rails app I need (e.g. ActiveRecord stuff only) so it doesn't load absolutely everything to run a few tests...

OpenID support for Ruby on Rails application

What is current state of the art for enabling OpenID login in Ruby on Rails applications? This is a community wiki with up-to-date answers to this question. Authlogic The most advanced authentication solution seems to be Authlogic. It supports OpenID with Authlogic OpenID plugin. It supports Rails 3.0 and 2.x. You may want to watch...

Using Rails 2.x with MS SQL Server 2005

Does anybody here have positive experience of working with MS SQL Server 2005 from Rails 2.x? Our developers use Mac OS X, and our production runs on Linux. For legacy reasons we should use MS SQL Server 2005. We're using ruby-odbc and are running into various problems, too depressing to list here. I get an impression that we're doin...

How to write a Rails mixin that spans across model, controller, and view.

In an effort to reduce code duplication in my little Rails app, I've been working on getting common code between my models into it's own separate module, so far so good. The model stuff is fairly easy, I just have to include the module at the beginning, e.g.: class Iso < Sale include Shared::TracksSerialNumberExtension include Shar...

rake db:migrate doesn't detect new migration ?

Experienced with Rails / ActiveRecord 2.1.1 You create a first version with (for example) ruby script\generate scaffold product title:string description:text image_url:string This create (for example) a migration file called 20080910122415_create_products.rb You apply the migration with rake db:migrate Now, you add a field to the produ...

How should Rails models containing database and non-database datasources be broken up?

So I'm working on a Rails app to get the feeling for the whole thing. I've got a Product model that's a standard ActiveRecord model. However, I also want to get some additional product info from Amazon ECS. So my complete model gets some of its info from the database and some from the web service. My question is, should I: Make two mod...

How does a Rails developer talk to Flex front ends?

I'm looking at Rails development as a backend to a Flex application and am trying to figure out the communication layer between the Rails app and the Flash Player. All of the things I am finding suggest using SOAP web services to communicate. However, Flash supports AMF which is nice and fast (and native). Is there any way of communic...

How do I set the HttpOnly flag on cookie in rails

The page http://www.codinghorror.com/blog/archives/001167.html explains why making HttpOnly cookies is a good idea How do I set this property in RubyOnRails ...

Refactoring in Ruby

Are there any programs or IDEs that support refactoring for Ruby or RoR? ...

What's the best option for searching in Ruby on Rails?

There are several plugin options for building a search engine into your Ruby on Rails application. Which of these is the best? Thinking Sphinx UltraSphinx Sphincter acts_as_sphinx acts_as_ferret Ferret acts_as_xapian acts_as_solr Hyper Estraier ...

How do you restart Rails under Mongrel, without stopping and starting Mongrel

Is there a way to restart the Rails app (e.g. when you've changed a plugin/config file) while Mongrel is running. Or alternatively quickly restart Mongrel. Mongrel gives these hints that you can but how do you do it? ** Signals ready. TERM => stop. USR2 => restart. INT => stop (no restart). ** Rails signals registered. HUP => reloa...

Why isn't there a viable mod_ruby for Apache yet?

As popular as Ruby and Rails are, it seems like this problem would already be solved. JRuby and mod_rails are all fine and dandy, but why isn't there an Apache mod for just straight Ruby? ...

What does BlazeDS Livecycle Data Services do, that something like PyAMF or RubyAMF not do?

I'm doing a tech review and looking at AMF integration with various backends (Rails, Python, Grails etc). Lots of options are out there, question is, what do the Adobe products do (BlazeDS etc) that something like RubyAMF / pyAMF don't? ...

Mongrel hangs with 100% CPU / EBADF (Bad file descriptor)

We have a server with 10 running mongrel_cluster instances with apache in front of them, and every now and then one or some of them hang. No activity is seen in the database (we're using activerecord sessions). Mysql with innodb tables. show innodb status shows no locks. show processlist shows nothing. The server is linux debian 4.0 Ru...