ruby

Asscociate action to on_change for form.select in Rails???

the following is my dropdown to select chat rooms: <% form_for :chat_room do |form| %> <%= form.select(:title, @chat_rooms.collect! {|x| x.title},{:include_blank =>'select a chat room'}) %> <% end %> My routes are: ActionController::Routing::Routes.draw do |map| map.resource :account, :controller => "users" map...

Validating a finite state machine (using AASM) on Rails.

I'm using AASM by Rubyist to build a 4-step wizard for an AR object. According to the state of the object, there are different validations that need to be done. What is the smartest way to validate an object according to it's state on a certain transition? ...

Message Queues in Ruby on Rails

What message queues are people using for their Rails apps and what was the driving force behind the decision to choose it. Does the latest Twitter publicity over their in house queue Starling falling down affect any existing design decisions. I am working on an app that will need a message queue to process some background tasks, I haven...

Extracting filenames from command line arguments with Ruby

I'm trying to use optparse to parse command line arguments. I would like my program to accept arguments like that: $ ./myscript.rb [options] filename I can easily manage the [options] part: require 'optparse' options = { :verbose => false, :type => :html } opts = OptionParser.new do |opts| opts.on('-v', '--verbose') do option...

ActiveRecord conditions Error

Hi, I have this: SectionHistory.find(:all, :conditions => ["id=? and (name!=? or code!=?)", sec.id, sec.name, sec.code]) And I get the error "The character "!" following "and (name!=? or code" is not valid" if my condition string is just "id=? and (name!=?)" it's OK We're using DB2. Any suggestions on this? Thanks ...

Full-screen Shoes application?

I looked around the documentation but found nothing - is there a way to make a Shoes app display full screen? Possibly something like.. Shoes.app :fullscreen => true do para "test" end Looking in the source-code, the following lines mentioning "fullscreen" (among others): shoes/app.c:58: app->fullscreen = FALSE; shoes/native/coco...

Whats the best method of creating "walled gardens" for multiple clients inside your database?

I'm setting up a SaaS style website wherein I will have multiple clients all managing their workflows and data on the same site -- and thus the same database. I'm not even sure if there is a word for this concept, but is there any established way of auto-segregating the data so that any ActiveRecord calls to the database are filtered/re...

Is there an analogue to Rails partials in VB .NET?

I'm new to VB .NET, and if possible, I'd like something like Rails partials - bits of HTML template that can be referenced in a page's script, possibly within a loop. I know there might not be anything like that. ...

how do I make the URL's in Ruby on Rails SEO friendly knowing a @vendor.name?

My application is in RoR I have an action/view called showsummary where the ID has been passed into the URL, and the controller has used that to instantiate @vendor where @vendor.name is the name of a company. I would like the URL to be, rather than showsummary/1/ to have /vendor-name in the URL instead. How do I do that? ...

Is it possible to put just a rails form element in a partial?

My app has a select box for users to choose a "venue". This select box is, as you would expect, in a form. I also have an action somewhere on the page that creates a new venue via AJAX. After the new venue is created, I would like to updated the venue select box to reflect this. My solution was to put the select box in a partial and ...

unable to save a model from rake task

Hi, I am writting a rake task that would connect to a legacy ORACLE database, get some 'issues' records from a helpdesk application, apply some transformation and store it in another database (Redmine). The problem is that even though the script runs smoothly on Windows, it fails to run on RHEL 5. The library files are all installed ...

How to restart Rails from within Rails?

Ok, so I would like to create an action in Rails to restart itself. I did a little searching and found: http://snippets.dzone.com/posts/show/5002 Which suggests 2 commands, one to stop and another to restart. The following kills: ps -a|grep "/usr/local/bin/ruby script/server"|grep -v "grep /usr"|cut -d " " -f1|xargs -n 1 kill -KILL ...

Easily backing up a long-running ruby process

I'm planning on running a ruby process that may take a month to finish. If possible, I'd like to ensure that a blackout or hitting the wrong button won't cost me the whole month's work. Is there an easy way to periodically save the program's state to disk? (Techniques that involve more effort would include adding code that marshals eve...

What exactly is Rake ?

Dear all In simple terms, what does Rake do? What purposes does it have? I understand it's a build tool but I'm looking a bit more detail. (For a simpleton.) Many thanks Skipz ...

Rails: Model method execution sequence

I have problem in my model. I want method to use another property of model but before using it I want another method to be executed (to make property have value). Here is an example: def medthod_one=(val) self.value = val end def method_two self.second_value = self.value / 2 #just for example end So, in my case self.second_...

Want to display an error message if the session is closed in rails

Hi there i want to display an error message if the session is closed, cause if i log in and and i press the go back at the top of the browser and then press the go forward and try to refresh the page it display an error message that it couldn't find the current user who was in the session and i want to display a page for handling that er...

When creating an object in Ruby on Rails, which method of saving do you prefer, and why?

When writing the "create" method for an object in a Ruby on Rails app, I have used two methods. I would like to use one method for the sake of cleaner and more consistent code. I will list the two methods below. Does anyone know if one is better than the other? If so, why? Method 1: def create1 # is this unsecure? should we grab ...

poll() in Ruby?

I am currently porting a self-written network application from C++ to Ruby. This network application often needs to manage around 10.000 sockets at the same time, that means it needs quick access to any sockets that have readable data available, incoming connections, etc. I have already experienced while writing it in C++, that select()...

Rails flash messages in Java

What's the best way to achieve Rails-like flash messages such as "Update successful" http://api.rubyonrails.org/classes/ActionController/Flash.html) in the Java world? I'm using Spring MVC. ...

How do I make beautiful screenshots of web pages using ruby and a unix server?

I'm trying to programatically create beautiful thumbnail images of a large number of web pages that are hosted on my own ruby/rails-based website. I want to be able to code a stand-alone bit of ruby that looks something like this: require 'awesome-screenshot-maker' items.each do |id| url = "http://foo.com/bar/#{id}" shooter = Awes...