ruby

Multi-nested attributes using accepts_nested_attributes_for does not update any but the first layer of nested objects

I have an interesting conundrum. I have a table of programs that has_many install_validations that have many install_validation_reactions (don't ask!). I set the program model to accepts_nested_attributes_for :install_validations, :allow_destroy => true, and the same between the install_validations and install_validation_reactions. Built...

wxRuby - change TextCtrl Style property

I'm brand new to wxRuby, and just trying to figure things out. How do I change the style of the TextCtrl after it has been created. tb = Wx::TextCtrl.new(panel, -1, :style => Wx::TE_PASSWORD) Sets the text input properly, but is it possible to change this property after it has been created? tb = Wx::TextCtrl.new(panel, -1) tb.set_wi...

Trouble importing csv file with ruby CSV Module

I'm trying to use Ruby's csv module to import the records contained in a csv file to my local table in a Ruby on Rails 3 application. The table was created through the creation of model Movie. Here is what I've been executing in console: require 'csv' CSV.foreach('public/uploads/VideoTitles2.csv') do |row| record = Movie.new( ...

File.open modes and options?

File.open takes modes and options as arguments. Where do I find a list of modes and options? ...

How to move from .NET-style TDD to Ruby?

I've been struggling to adapt my standard approach for test-driving .NET code to Ruby. As an example, I am writing a class that will: grab all *.markdown files from a directory foreach file: extract code samples from file save code to file.cs in output directory Normally for .NET I'd end up with something like: class Examp...

Rails.root is Empty in Custom Rake Task in Rails 3.0

Maybe I missed this in the upgrade documentation, but if I output "Rails.root" in the rails console I see my app's root path. But if I reference "Rails.root" in a custom Rake task, it's empty. What am I missing? Thanks in advance. Sample: namespace :admin do desc "Import some data" task :import => :environment do csv = ...

Running a shell command from Ruby: capturing the output while displaying the output?

I have a problem. I want to run a ruby script from another ruby script and capture it's output information while letting it output to the screen too. runner #!/usr/bin/env ruby print "Enter your password: " password = gets.chomp puts "Here is your password: #{password}" The script file that I run: start.rb output = `runner` puts o...

How can I configure gem to only ever use system gems?

I want to configure gem to only use system gems - never those in $HOME/.gem. This is because I'm writing a script that will access Gem.path and I don't want it to return the path to gems in my home directory. I'm pretty sure I haven't explicitly set GEM_HOME or anything like that in my .bashrc, .bash_login etc. But Gem.path returns my ...

Combo list is not able to write in db

I'm trying to write in db an id from another tableI have a machine table that belongs to owner table. Models: class Machine < ActiveRecord::Base has_many :ipvfours, :dependent => :destroy belongs_to :owners accepts_nested_attributes_for :ipvfours #accepts_nested_attributes_for :owners # some check on fields validates_uniqu...

How to strip out invalid UTF-8 characters in Ruby 1.9

I just upgraded from Ruby 1.8 to 1.9, and most of my text processing scripts now fail with the error invalid byte sequence in UTF-8. I need to either strip out the invalid characters or specify that Ruby should use ASCII encoding instead (or whatever encoding the C stdio functions write, which is how the files were produced) -- how would...

Problems With Simple captcha.

I have a weird issue .I am using simple captcha in forms in my rails applications. If I am using one captcha in a web page I don't have any problem. But I have a scenario of using three(3) forms in one page in which all the three forms will have the captcha . So that when I refresh the page the captcha data of the three forms are equal....

Missing RedCloth gem but `rake gems:install` does nothing

I tried starting my Rails application but got this error message from Passenger: Ruby on Rails application could not be started The application has exited during startup (i.e. during the evaluation of config/environment.rb) /home/chuck/chuck.com/vendor/rails/railties/lib/rails/gem_dependency.rb:119: Warning: Gem::Dependency#version_...

Problem with gem sources - bad gateway 502 on rubygems.org

Hello. Just wondering if anybody had the same problem with rubygems.org I appluad the decision to consolidated everything on rubygems.org, but when the default was rubyforge - I never had any problems. Now it seems I have a problem updating gems everytime I do a new installation. I mean I can work around it, but downloading gems throug...

ActionMailer outside Rails 3. Anyone found a good tutorial?

Curious if anyone has seen any good references for using the new ActionMailer outside the rails framework. Thanks. ...

How do I get RubyGems to work with Jruby and JBOSS; works with Tomcat but not JBoss

I have a WAR file that uses jruby-complete.1.5.2.jar to provide JRuby as a ScriptEngine. My JRuby script relies on some Ruby gems that I packaged in a jar file. This works fine when I run the WAR file under Tomcat, but it does NOT work when I use JBoss 5.1.0. To trouble shoot, I even tried running a simple script that required the "ra...

How to create directories recursively in ruby?

I want to store a file as /a/b/c/d.txt, but I do not know if any of these directories exist and need to recursively create them if necessary. How can one do this in ruby? ...

ROR: i18n best practices for large translation dictionaries

When internationalizing a rails app, what is the best practice way for organizing/scoping translations in the dictionary files? Under what circumstance should you use interpolations of variables? Should every phrase be it's entry? Is there anyone who participated in dhh's tolk who can shed some light on how 37signals broke up their d...

Passing blocks into nested method within class_eval in Ruby?

I want to be able to define a block, and later evaluate that block from within a dynamically generated module/class. It seems like I could accomplish this somehow using eval and block.binding, but I haven't figured it out. I have this as the base: def define_module(name, &block) name = name.to_s.gsub(/\/(.?)/) { "::#{$1.upcase}" }.g...

Can Ruby interface with r?

A friend needs to do some R programming for her PhD and since I'm a programmer, asked me to give her a hand. So I took a look at some r related webstuff and discovered that you can interact with it through RPy (python) and statistics::R (perl). Is there a way for Rubyists to hook into R? Is there a dipsh*t's guide to learning R (lik...

Determining if an array of strings contains a certain substring in ruby

Hi all- I have a simple ruby question. I have an array of strings. I'd like to determine if that array contains a substring of any of the strings. As an example a = ['cat','dog','elephant'] a.to_s.include?('ele') Is this the best way to do it? Thanks. ...