ruby-on-rails

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...

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 ...

Need to run a TCP server besides a Rails app

Hi, I have a Rails 2.0.2 application running with a postgresql db. The machine will receive data on a TCP port. I already have coded a working ruby multithreaded tcp server to receive the requests, but I need this code to run alongside my Rails app. So I guess I need to know how to span a new process inside Rails, or how to create a wo...

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...

Migrations for Java

I use both ruby on rails and Java. I really enjoy using migrations when I am working on a rails project. so I am wondering is there a migrations like tool for Java? If there is no such tool is it a good idea to use migrations as a tool to control a database used by a Java project? ...

Backgroundrb scheduled task ending

I have a backroundrb scheduled task that takes quite a long time to run. However it seems that the process is ending after only 2.5 minutes. My background.yml file: :schedules: :named_worker: :task_name: :trigger_args: 0 0 12 * * * * :data: input_data I have zero activity on the server when the process is running. (...

Preventing Mongrel/Mysql Errno::EPIPE exceptions

I have a rails app that I have serving up XML on an infrequent basis. This is being run with mongrel and mysql. I've found that if I don't exercise the app for longer than a few hours it goes dead and starts throwing Errno::EPIPE errors. It seems that the mysql connection get timed out for inactivity or something like that. It can be re...

Problem with ar_mailer

Hi guys, I'm running a strange problem sending emails. Basicly I'm getting this exception: ArgumentError (wrong number of arguments (1 for 0)): /usr/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/active_record/base.rb:642:in `initialize' /usr/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/active_record/base.rb:642:in `new' /usr/lib/ruby/...

Installing mysql problem

Running OS X Leopard an MacBook Pro from Jan. 2008. I used to run mysql server from a package but then rails started putting a warning that I should install mysql from gem: gem install mysql It did not work, I got the following error message: Building native extensions. This could take a while... ERROR: Error installing mysql: ER...

How do you find the namespace/module name programatically in Ruby on Rails?

How do I find the name of the namespace or module 'Foo' in the filter below? class ApplicationController < ActionController::Base def get_module_name @module_name = ??? end end class Foo::BarController < ApplicationController before_filter :get_module_name end ...

Good idea to access session in observer or not?

I want to log user's actions in my Ruby on Rails application. So far, I have a model observer that inserts logs to the database after updates and creates. In order to store which user performed the action that was logged, I require access to the session but that is problematic. Firstly, it breaks the MVC model. Secondly, techniques ran...

Why shouldn't Helpers have html in them?

I have heard that it's best not to actually have any html in your helpers; my question is, Why not? And furthermore, if you were trying to generate an html list or something like that, how can I avoid actual tags? Thanks! -fREW ...

Who's using Ruby on Rails in production?

I've been kicking around Ruby and the rails framework and have been considering recommending to a client-of-a-client that they use it to rebuild their site, which is currently built in very bad ASP classic that will have to be rewritten from the ground up regardless of what technology is used. One thing I'm missing from my pitch is a li...