ruby

Ruby: Why does 'and not' work when '&& !(expr)' does not?

I have an if statement in my Rails app. I need to do a basic "if true and !false" sort of check. The expression is defined as: ActiveRecord::Base.connection.tables.include? 'settings' && !Settings.setting_is_set?('defaults_set') If I put that as my expression to an if, the if will not trigger. If I run that expression in the console, ...

Nested forms in rails = has_many :confusions :(

I have a user and a profile model. One user can have many profiles. I need to access only one information from the profiles section (viz the phone number) in my user model during the user creation process. Hence I'm trying to get it done through attr_accessible. My user.rb looks like this. has_many :profiles attr_accessible :handle, :em...

Ruby Watir: Clicking OK on JavaScript Alerts?

Seems none of the code I've tried has any affect. My intention is to close any and all JavaScript prompts that may come up by hitting the "OK" button. Problem is, my script has no affect on the prompts that come up. In other words, it does nothing. Here's what I have: fx = FireWatir::Firefox.start(somepage) fx.startClicker("OK") fx.but...

`if __name__ == '__main__'` equivalent in Ruby

I am new to Ruby. I'm looking to import functions from a module that contains a tool I want to continue using separately. In Python I would simply do this: def a(): ... def b(): ... if __name__ == '__main__': a() b() This allows me to run the program or import it as a module to use a() and/or b() separately. What's ...

Ruby on rails: put a link in a flash[:notice]

I am in the beginning stages of learning ruby and RoR. I have a Ruby on Rails project that tracks jobs a server is running. Right now, when you manually create a new job, it announces flash[:notice] = "Created job job number #{update.id}." I would like to turn the #{update.id} into a link to the job on the job list. The URL for goi...

cuke4nuke install issues

Anyone else having trouble installing cuke4nuke via gem install cuke4nuke? I'm getting the following error and can't figure out what to do to solve it: Building native extensions. This could take a while... ERROR: Error installing cuke4nuke: ERROR: Failed to build gem native extension. C:/Ruby/bin/ruby.exe extconf.rb checki...

Coming From Ruby To Visual C# 2008: Good Resources?

I'm a Ruby programmer and I've gotten pretty used to the "ruby" style of programming; such as duck typing. Are there any good resources for learning Visual C# 2008 coming from a Ruby background? ...

Simple ruby unless method error, ROR

Assume the require_role ["alt", "student worker"], :except => [:list, :show, :index, :create] works outside of this method, what am I doing wrong here? When I call the method it works while it is a promo_site? (true), but when it is false the method fails. def check_if_role_is_required require_role ["alt", "student worker"], :exc...

Why does Kernel#p print to standard out?

Why does Kernel#p print to standard out? Isn't printf debugging supposed to output to standard error? ...

Basic ruby question: the { } vs do/end construct for blocks.

Possible Duplicates: Using do block vs brackets {} What is the difference or value of these block coding styles in Ruby? Why does: test = [1, 1, 1].collect do |te| te + 10 end puts test Works, but not: puts test = [1, 1, 1].collect do |te| te + 10 end And yet this works: puts test = [1, 1, 1].collect { |te| ...

ruby array pack and unpack functionality in javascript?

What are the Javascript functions or libraries that are equivalent to Ruby's pack and unpack functions for the Array class? I'm particularly interested in converting hex strings to strings. irb(main):022:0> ["446f67"].pack("H*") => "Dog" I'm not a javascript programmer and would rather not roll my own converter if libraries are availa...

How many Rails apps on 1 Heroku dyno?

I just can't find how many apps you can host on heroku with one dyno? I plan to host a lot of small apps with little traffic. Thanks for your answers ...

Installing gems inside (J)Ruby code

I am using JRuby along with Cucumber and is looking for a way of running jruby -S gem update --system jruby -S gem install cucumber from within the Java ScriptEngine. No amount of Googling have let me to a solution to this problem. Basically I want to be able to do something like this ScriptEngineManager manager = new ScriptEngin...

Flash communication options for 2-player-games

I am currently working on a project that embeds a flash game, that uses Smartfoxserver for the flash communication. That communication is mostly just synchronizing the cursor and object movements between the two players. Since I am not a flash guy, but a ruby programmer, I got curious: What kind of communication options does flash offer...

Plain Old Objects in Ruby?

I notice in Ruby it is very common to for vendor APIs to pass back results as arrays? Shouldn't Plain Old Objects (Like POJOs in Java) be more of a standard? If I write my own library shouldn't I use POJOs POROs? ...

Ruby Noob? create a ruby date

I have to convert several ASCII binary files over to MySQL. These files and records contain several 6 digit fields representing dates in the form of 090403 (yymmdd) and I would like to convert them to 2009-04-03. How do i create a date object with this input? ...

Weighted nested set

Are there any gems or plugins that offer a nested set but with a weight also. I want to be able to create a nested set and order each subset by its weight. ...

attachment_fu and multipart form_for

Woo. My first question. I have a feeling I'm overlooking something pretty basic in the construction of my form. I'm using attachment_fu and can't get this form to pass anything besides the file data. A user has_many profiles and a profile has_many documents. My form looks like this: <%= error_messages_for :document %> <% form_for([@...

Pass email to a script : STDOUT question

I am catching emails to "script@localhost" with /etc/aliases: script: root,"|/path-to-my-script" this gets an email on STDIN and I am parsing and passing it to other scripts. #!/usr/bin/ruby email = ARGF.read ...parse...parse-some-more... system("/my-other-script.sh #{email.todo}") the question is - what would be a best way to ca...

Catch a Ruby exception for logging, but don't throw it?

I seem to be having a brain freeze. I want to catch a possible Ruby exception during a loop through several objects in order to count it as a failure for displaying later, but I do not want execution halted; I want it to skip the bad record and continue. How do I do this again? I don't think I can use retry because that would try the ...