ruby

cannot install rails plugins

My problem is: ruby script/plugin is not working (I don't see any HTTP traffic, nor an error message or something) What can be failing? Did I forget to setup something? My progress so far (using Windows XP): Unpacked hxxp://files.rubyforge.vm.bytemark.co.uk/rubyinstaller/ruby-1.9.1-p378-i386-mingw32.7z (to d:\prog\Ruby) Unpacked hxxp:...

Whitespace Between Tags in HAML

Is there a way to specify "pretty-print"-like formatting around HTML tags? I want to be able to put whitespace between blocks of HTML, so this: <!-- container --> <div id='container'> </div> <!-- footer --> <div id="footer"> </div> <!-- analytics --> ... ...is converted to this: <!-- container --> <div id='container'> </div> <!-- ...

Why does my rails project not have the ruby standard lib in $LOAD_PATH on OSX?

I need to do a: require 'generator' Inside of a rails project, but it is not working for me on OSX, because the ruby standard library (which is located in my /usr/lib/ruby/1.8) is not in my $LOAD_PATH once rails boots. If I just run irb outside of rails it is there. Where/What do I need to config? ...

Which key value store is the most promising/stable?

I'm looking to start using a key/value store for some side projects (mostly as a learning experience), but so many have popped up in the recent past that I've got no idea where to begin. Just listing from memory, I can think of: CouchDB MongoDB Riak Redis Tokyo Cabinet Berkeley DB Cassandra MemcacheDB And I'm sure that there are mor...

Data integrity when updating/incrementing values in Rails

I am working on an application in which one module accesses a log (an ActiveRecord model) to increment various values at several points of the execution. The problem is that the script is likely to take several seconds, and other instances of the same script is likely to run at the same time. What I'm seeing is that while the script fin...

Ruby private instance variables, with exceptions

I am making a card game in ruby. I have the Game class, which has an array of Player objects. array_of_players = Array[ Player.new("Ben"), Player.new("Adam"), Player.new("Peter"), Player.new("Fred"), ] my_game = Game.new(array_of_players) puts my_game.players[2].name #=> Peter Each player also has access to the Game, so ...

[Ruby/Rails] How to execute code stored in DB?

Basically, I have an RPG-type Rails application. I'm storing skills in a skills database with the following fields: name, min_level, skill_type, formula My formula is stored as a String, currently. The idea is to have it say something like "1000*min_level" and somehow run it to calculate the skill damage. Is there any good way to do th...

Convert durations in Ruby - hh:mm:ss.sss to milliseconds and vice versa

Hey there, I was wondering if there is a built-in method in Ruby that allows me to convert lap times in the format of hh:mm:ss.sss to milliseconds and vice versa. Since I need to do some calculations with it, I assumed that converting to milliseconds would be the easiest way to do this. Tell me if I am wrong here :) Cheers, Chris ...

mocha and nested objects

Excuse if this is a silly question, I am new to mocking. I am able to use mocha to do things like: person.expects(:first_name).returns('David') How can I mock a nested object? Say I have a Product that belongs to a Person and I want to get the first name of that person. In my app I might do it like this: product.person.first_name ...

prawn PDF: I need to generate nested tables

I need a table where rows are actually 2 rows tables, a nested table that is.. How can I do that in prawn? Maybe I need an extension.. but which one? ...

special string splitting in Ruby

Hi I am trying to figure out the best way to do this... Given a string s = "if someBool || x==1 && y!=22314" I'd like to use Ruby to seperate statements and boolean operators.. so I'd like to split this into ["if","someBool","||","x","==","1","&&","y","!=","22314"] I could use s.split(), but this only splits with space as delim...

XML fetching and parsing solution/library that works with Ruby 1.9.1 on Rails 3

Does anyone know of a library that works with Ruby 1.9.1 on Rails 3 yet? Thanks, Nick ...

How to use Ruby Mechanize to automatically like Facebook posts

Hi, I'm trying create a bot which automatically "likes" Facebook posts. Using Mechanize I can log into facebook, but unforunately the links to the like button are not understood by Mechanize - they seem to be obsfuscated by JS. The only links I see are the basics such as: <Mechanize::Page::Link "Edit friends" "http://www.facebook.co...

Ruby String accent error: More than meet the eyes

I'm having a real trouble to get accents right, and I believe this may happen to most Latin languages, in my case, portuguese I have a string that come as parameter and I must get the first letter and upcase it! That should be trivial in ruby, but here is the catch: s1 = 'alow'; s1.size #=> 4 s2 = 'álow'; s2.size #=> 5 s1[0,1] #=> "a"...

Vestal_versions and acts_as_taggable_on

Hi, Does anybody successfully integrated vestal versions and acts_as_taggable_on plugins? I've added to my app, that using acts_as_taggable_on following line to environment.rb config.gem 'vestal_versions' and on any rake task or generator script call i see $ ./script/generate /opt/local/lib/ruby/gems/1.8/gems/rails-2.3.5/lib/rails/...

Ruby parse string

I have a string input = "maybe (this is | that was) some ((nice | ugly) (day |night) | (strange (weather | time)))" How is the best method in Ruby to parse this string ? I mean the script should be able to build sententes like this : maybe this is some ugly night maybe that was some nice night maybe this was some strang...

vi input mode in command line Matlab?

I have these lines in my ~/.inputrc: set editing-mode vi set keymap vi This allows me to use vi keybindings in every program that uses GNU readlines for text input. Examples: python, irb, sftp, bash, sqlite3, and so on. It makes working with a command line a breeze. Matlab doesn't use readlines, but vi keybindings would be amazing...

Creating a setter method that takes extra arguments in Ruby

I'm trying to write a method that acts as a setter and takes some extra arguments besides the assigned value. Silly example: class WordGenerator def []=(letter, position, allowed) puts "#{letter}#{allowed ? ' now' : ' no longer'} allowed at #{position}" end def allow=(letter, position, allowed) # ... end end Writing i...

How to create a full Audit log in Rails for every table?

We recently began a compliance push at our company and are required to keep a full history of changes to our data which is currently managed in a Rails application. We've been given the OK to simply push something descriptive for every action to a log file, which is a fairly unobtrusive way to go. My inclination is to do something like...

A website using Ruby alone.

I want to write a web application and want to use Ruby. I have no knowledge of Ruby as of now and I want to write this app. to learn Ruby. Is Ruby alone sufficient to write a web application or Rails need to be included? ...