ruby

Rails Check box on MySql stored as a null or zero

On my rails app I have a list of items (like a task list) and for each item there is a couple of check box to set parameters. When I submit the form, the checked box are stored as zero and the unchecked as null on DB. the question is: Is there a way to configure it? To store the data on a more traditional 0 or 1, because I think that ...

How to change "3 errors prohibited this foobar from being saved" validation message in Rails?

In my rails app I use the validation helpers in my active record objects and they are great. When there is a problem I see the standard "3 errors prohibited this foobar from being saved" on my web page along with the individual problems. Is there any way I can override this default message with my own? ...

Why do I get an error when starting ruby on rails app with mongrel_rails

Why do I get following error when trying to start a ruby on rails application with mongrel_rails start? C:\RailsTest\cookbook2>mongrel_rails start ** WARNING: Win32 does not support daemon mode. ** Daemonized, any open files are closed. Look at log/mongrel.pid and log/mongr el.log for info. ** Starting Mongrel listening at 0.0.0.0:30...

Need advice: Structure of Rails views for submenus?

Imagine to have two RESTful controllers (UsersController, OffersController) and a PagesController (used for static content such as index, about and so on) in your application. You have the following routes defined: map.with_options :controller => 'pages' do |pages| pages.root :action => 'index' # static home page pages.about :a...

What is the best way in Rails to determine if two (or more) given URLs (as strings or hash options) are equal?

I'm wanting a method called same_url? that will return true if the passed in URLs are equal. The passed in URLs might be either params options hash or strings. same_url?({:controller => :foo, :action => :bar}, "http://www.example.com/foo/bar") # => true The Rails Framework helper current_page? seems like a good starting point but I'd ...

Which Ruby XML library would you recommend for a 2.4MB XML file?

I have a 2.4 MB XML file, an export from Microsoft Project (hey I'm the victim here!) from which I am requested to extract certain details for re-presentation. Ignoring the intelligence or otherwise of the request, which library should I try first from a Ruby perspective? I'm aware of the following (in no particular order): REXML Chil...

Ruby on Rails - Why use tests?

I'm confused about what the various testing appliances in Ruby on Rails are for. I have been using the framework for about 6 months but I've never understood the testing part of it. The only testing I've used is JUnit3 in Java and that only briefly. Everything I've read about it just shows testing validations. Shouldn't the validations ...

Best Practices for reusing code between controllers in Ruby on Rails

I have some controller methods I'd like to share. What is the best practice for doing this in ruby on rails? Should I create an abstract class that my controllers extend, or should I create module and add it in to each controller? Below are the controller methods I want to share: def driving_directions @address_to = params[:address_to...

Ruby error "Superclass mismatch for for class Cookie" from cgi.rb

I've just updated my ruby installation on my gentoo server to ruby 1.8.6 patchlevel 287 and have started getting an error on one of my eRuby apps. The error given in the apache error_log file is: [error] mod_ruby: /usr/lib/ruby/1.8/cgi.rb:774: superclass mismatch for class Cookie (TypeError) The strange thing is that it seems to work ...

How can I make Ruby's SOAP::RPC::Driver work with self signed certificates?

How can I prevent this exception when making a soap call to a server that is using a self signed certificate? require "rubygems" gem "httpclient", "2.1.2" require 'http-access2' require 'soap/rpc/driver' client = SOAP::RPC::Driver.new( url, 'http://removed' ) client.options[ 'protocol.http.ssl_config.verify_mode' ] = OpenSSL::SSL::VERIF...

Is there a way to have class variables with setter/getter like virtual variables?

I am embedding Ruby into my C project and want to load several files that define a class inherited from my own parent class. Each inherited class needs to set some variables on initialization and I don't want to have two different variables for Ruby and C. Is there a way to define a class variable that has an own custom setter/getter or...

Cap invoke and sudo

I want to install a gem on all my application servers, but gem install requires sudo access - how can I enable sudo only for running this capistrano command? In other words, I don't wish to use sudo for all my deployment recipes, just when I invoke this command on the command line. ...

Best place in spec/ for integration responses?

I have some integration points where I want to test various responses - where do you think should I store these artifacts in my spec/ directory of my rails application? ...

Is it possible to compile a Rails app to a Java VM JAR file?

Essentially the only thing I can deploy to my deployment machine is a JAR file. I can't install JRuby, nor can I install Glassfish or Tomcat. Is it possible to package up a Rails application (including Rails, vendored, of course) to a JAR file such that I can do c:\my_server> java rails_app.jar and have it run WEBRick or Mongrel wit...

What are the current state of affairs on threading, concurrency and forked processes, in Ruby on Rails?

Ruby on Rails does not do multithreaded request-responses very well, or at least, ActiveRecord doesn't. The notion of only one request-response active at the same time can be a hassle when creating web applications which fork off a shell-command that takes long to finish. What I'd like are some of your views on these kinds of setups? I...

Is it a bad idea to reload routes dynamically in Rails?

I have an application I'm writing where I'm allowing the administrators to add aliases for pages, categories, etc, and I would like to use a different controller/action depending on the alias (without redirecting, and I've found that render doesn't actually call the method. I just renders the template). I have tried a catch all route, bu...

Should I start with Ruby or Ruby On Rails?

I've been wanting to learn Ruby for a long time since there seems to be alot of buzz about it the last couple years. From what I've seen/read there have been a few Ruby'esk things that have been brought over the .NET too. Should I start with learning the Ruby language and just focus on writing simple command-line apps first? Or, should ...

CouchDB Document Model Changes?

Rails uses the concept of migrations to deal with model changes using the ActiveRecord API. CouchDB uses JSON (nested maps and arrays) to represent its model objects. In working with CouchDB so far, I don't see good ways of recognizing when the document's structure has changed (other than being disciplined as a developer), or for migra...

How to eager load objects with a custom join in rails?

Background Normal rails eager-loading of collections works like this: Person.find(:all, :include=>:companies) This generates some sql which does LEFT OUTER JOIN companies ON people.company_id = companies.id Question However, I need a custom join (this could also arise if I was using find_by_sql) so I can't use the vanilla :includ...

Setting up Rails to work with sqlserver

Ok I followed the steps for setting up ruby and rails on my Vista machine and I am having a problem connecting to the database. Contents of database.yml development: adapter: sqlserver database: APPS_SETUP Host: WindowsVT06\SQLEXPRESS Username: se Password: paswd Run rake db:migrate from myapp directory ---------- rake abo...