ruby

Why can't I install the sqlite gem?

I'm try to install the sqlite gem on a Fedora 9 Linux box with ruby 1.8.6, Rails 2.2.2, gem 1.3, and sqlite-3.5.9. Here's the command I'm running and its results: sudo gem install sqlite3-ruby Building native extensions. This could take a while... ERROR: Error installing sqlite3-ruby: ERROR: Failed to build gem native extension. ...

Anonymous users in Rails -- security considerations?

I'm looking at implementing some form of anonymous user system in Rails. I need to let people do things (creating records, looking at what they've created, etc), without actually creating an account. Once they create an account, everything persists without risk of losing it by clearing cookies or something. Right now, I'm thinking it's ...

Rails: submitting a form with multiple objects

I'm creating a Rails application, and I've hit a bit of a snag. I want a "create new record for DataType1" form that not only creates a new row for DataType1, but also inserts up to four new rows for DataType2. I know all about fields_for, but my problem is that I need to submit up to four DataType2s, and the only connection they have t...

How can I dynamically add a method to the Math class in Ruby on Rails?

I am trying to add the following method to the Math class in Ruby on Rails: class Math def self.round_with_precision(number, precision) scalar = 10.0 ** precision number = number * scalar number = number.round number = number / scalar return number; end end I then added the following to my environment.rb: requ...

Is there a Javascript equivalent of Ruby's andand?

In trying to make my Javascript unobtrusive, I'm using onLoads to add functionality to <input>s and such. With Dojo, this looks something like: var coolInput = dojo.byId('cool_input'); if(coolInput) { dojo.addOnLoad(function() { coolInput.onkeyup = function() { ... }; }); } Or, approximately equivalently: dojo.addOnLoad(func...

ruby: can a block affect local variables in a method?

I'm just learning ruby and trying to understand the scope of code executed in blocks. For example, I want to be able to create a block that affects the method that it is attached to, like so: def test(&block) block.call() if block_given? puts "in test, foo is #{foo}" puts "in test, bar is #{bar}" end test() { foo="this is foo" ...

Ruby on Rails Ajax rubberband

I want my users to be able to do a rubberband selection in a image for a Ruby on Rails application. Has anyone seen any good plugins that do this or make it easy for me to implement it? ...

Ruby Object Member Access: How's that Done?

Having looked at this question: http://stackoverflow.com/questions/354547/print-ruby-object-members I have a related issue. I'm relatively new to Ruby, so this is hopefully blindingly obvious. I have what I believe to be a Ruby object, generated from the MIME::Types library. I'm looking to get a simple file type for a particular file. ...

Rails form validation conditional bypass

I have a rails model that validates uniqueness of 2 form values. If these 2 values aren't unique the validation errors are shows and the "submit" button is changed to "resubmit". I want to allow a user to click the "resubmit" button and bypass the model validation. I want to do something like this from the rails validation documentat...

Best way in MySQL or Rails to get AVG per day within a specific date range

Hey guys, I'm trying to make a graph in Rails, for example the avg sales amount per day for each day in a given date range Say I have a products_sold model which has a "sales_price" float attribute. But if a specific day has no sales (e.g none in the model/db), I want to return simply 0. What's the best way in MySQL/Rails to get this ...

Using a #! comment in ruby running in Ubuntu

I am new to programming and am trying to follow an example which uses #! comment in ruby. I am consistently get the message: bash: matz.rb: command not found I am using this comment: #! /usr/bin/env ruby I have tried it with and without the space after ! as well as with and without the env. when I use the $ which ruby r...

Would it be better to use collect in this situation?

I'm just starting out using Ruby and I've written a bit of code to do basic parsing of a CSV file (Line is a basic class, omitted for brevity): class File def each_csv each do |line| yield line.split(",") end end end lines = Array.new File.open("some.csv") do |file| file.each_csv do |csv| lines << Line.new(:...

RDoc CONSTANT comments?

In RDoc, is there any way to show constant comments? I would like to comment a constant in a project of mine but and realizing that they dont show up in the RDoc output. I checked documentation which is likely to have comments for their constants, but never saw any (http://www.ruby-doc.org/core/classes/Math.html). It's possible that the...

Using .gemspec version in documentation/library/script

So, I've been writing a bunch of ruby gems recently, and one thing I would find convenient is to include the current version (as specified in the gemspec) in the rdoc-generated documentation for my libraries, and in the OptionParser-generated --help sections used by my scripts (which I'm distributing via gem). Any way I can make it easy...

How Do I add a local Mysql user for Rails Dev?

I have a problem where I always need to give simple access to my local account, and don't want to deal with typing in my root password a million times on my local machine. How do I give perms so i can type 'mysql' with my local user and get access to everything? ...

Rails: modify form parameters before modifying the database

I'm working on a Rails app that sends data through a form. I want to modify some of the "parameters" of the form after the form sends, but before it is processed. What I have right now {"commit"=>"Create", "authenticity_token"=>"0000000000000000000000000" "page"=>{ "body"=>"TEST", "link_attributes"=>[ {"action"=>"Foo"...

How can I debug a single ruby script in netbeans?

All of this is on a windows xp box: Netbeans managed to accept an existing rails project and allowed me to debug it just fine, but my project has a number of processing scripts that handle non-MVC aspects. The rails project is just a system for queuing requests for the execution of these scripts. I've attempted to create netbeans proj...

Ruby Gems Problem: uninitialized constant Gem::GemRunner

Hi, I had a rails 2.2 app running, when I tried to add the latest rspec plugin to it. I did that checking it from github with the script/plugin install command. That made some rake task to stop working, I googled for a while and found that I had to upgrade RubyGems. I did that and got the following error: uninitialized constant Gem::Ge...

Comparing Strings in Ruby

I need to take two strings, compare them, and print the difference between them. So say I have: teamOne = "Billy, Frankie, Stevie, John" teamTwo = "Billy, Frankie, Stevie" $ teamOne.eql? teamTwo => false I want to say "If the two strings are not equal, print whatever it is that is different between them. In this case, I'm just look...

PyObjc vs RubyCocoa for Mac development: Which is more mature?

I've been wanting to have a play with either Ruby or Python while at the same time I've been wanting to do a bit of Cocoa programming. So I thought the best way to achieve both these goals is to develop something using either a Ruby or Python to Objective-C bridge (PyObjc or RubyCocoa). I know that ideally to get the best learning exp...