ruby

Ruby Datamapper stored decimals displaying in scientific notation

I have a model, called delivery: property :id, Serial property :created_at, DateTime property :updated_at, DateTime property :price, BigDecimal, :precision => 10, :scale => 2 Delivery has a price, which when viewed in SQLite is values such as 5.49, 6.95, 4.95 When displaying this information in the output (coded in ...

Rails 3 - IF a variable contains a part of the URL ?

Hello, i have a variable like /projects/3/blah blah or /projects/3 or just /projects What I'd like to do is have an IF statement in Rails like this: IF urlPath contains /projects proceed Does Rails / Ruby have a method for that? Also, likely it shouldn't have a false positive for something like /books/projects or /authors/mr-projects/...

Ruby color generator

I need to randomly generate colors for multiple items in a to do list. (like pick up the kids from school, pick up the dry cleaning and so on) What's the best way of doing this in ruby and also avoid colors that would be hard to see (like grey, white, and so on)? ...

Continuously Check Time

Firstly, how can I have jQuery continuously check the time, and add an id to a <div> tag if the current time is in between two set times? I'm making a clock for a school (where the clock is a website sent over cable to TVs in every room), where each period is expressed like this: <div class="period 1">Period 1: 7:32-8:14</div> I'm get...

Rails3: Cloning already-validated object prevents clone being invalidated -- is this strange or normal?

In Rails (3.0) test code, I've cloned an object so I can clobber it for validation testing without changing the original. If I have called assert(original.valid?) before cloning, then the clone passes the validates_presence_of test even after I have set member_id value to nil. The two tests below illustrate this. In test one, the clone...

sqlite3-ruby gem can't find sqlite3.h on ubuntu

Trying to get Rails up on ubuntu, and I’m having trouble installing sqlite3-ruby – it apparently can’t find sqlite3.h. All the references I can find to the error suggest the problem is either: sqlite3 headers aren’t installed, or make can’t find them. It looks to me like I’ve solved both those issues and I’m still seeing the same problem...

Why is ruby's PTY library failing to capture input when the shell has subprocesses?

I am writing a terminal emulator in ruby using the PTY library. /dev/tty0 is a device file connected to a keyboard. I am spawning the shell like this: shell = PTY.spawn 'env TERM=ansi COLUMNS=63 LINES=21 sh -i < /dev/tty0' It mostly works, but when a subprocess is started in the shell, shell[0] is not outputting the keyboard input to ...

Is there a way to list the available variables in an Ruby ERB template?

Hi All, Suppose I have a Ruby ERB template named my_template.html.erb, and it contains the following: <div><%= @div_1 %></div> <div><%= @div_2 %></div> <div><%= @div_3 %></div> Is there a way I can programatically list out all the available variables in the template? For example, the following method: def list_out_variables templ...

How to enable 'Click to toggle source' button' in Ruby RDoc.

When using the Darkfish RDoc generator to generate RDoc documentation, next to methods there is a Click to toggle source button next to each method. It isn't working for me when I generate my documentation, so how do you get that feature to work, do you have to add a keyword into your RDoc source or something? ...

What does ||= mean in Ruby?

Possible Duplicate: What does ||= mean in Ruby? What does ||= mean in Ruby? ...

140 Characters, is that a string or text?

Hey guys, just doing a quick scaffold on rails, and I'm going to have a field that's only 140 characters or less, is that a string or text? ...

Trying to learn RoR, but keep getting Page doesn't exist errors

I'm trying to learn RoR and I keep getting pesky page doesn't exist pages. I deleted the index.html file out of my public folder and created a root route in my routes file but I still am getting that error. I am running ubuntu 10.04 with mod_passenger and ruby enterprise edition. ...

why doesn't my refactored ruby using inject work?

I tried to do some refactoring to convert an each block into an inject, but it didn't work and I don't understand why. Here's the code that works before refactoring: class String # Build the word profile for the given word. The word profile is an array of # 26 integers -- each integer is a count of the number of times each letter ...

How to catch Errno::ECONNRESET class in "case when"?

My application (Ruby 1.9.2) may raise different exceptions, including net-connection breaks. I rescue Exception => e, then do case/when to handle them in defferent ways, but several errors go through my cases straight to else. rescue Exception => e p e.class case e.class when Errno::ECONNRESET p 1 whe...

Difference between class variables and class instance variables?

Can anyone tell me about the difference between class variables and class instance variables? Would be thankful.... ...

How I can call specified first app's rake task from second one.

How can I call specified 1st app's rake task from second one. Case: User on baseapp.com (RoR), fills up the reg.form BaseApp validates and stores data Than, with delayed_job/resque I should call subapp's rake db:bootstrap FORM_PARAM1 FORM_PARAM2 ... FORM_PARAM3 ...

User login while testing with rspec and authlogic

I have a spec for testing a controller as below require 'spec_helper' describe ProductsController do setup :activate_authlogic describe "user not logged in" do it "should not GET index" do get :index response.should redirect_to(login_path) end end describe "user logged in" do before(:each) do UserSession.create :username => "rohit...

How can I make Paperclip process files from a server directory?

I want to run Paperclip on all files in a directory on the server. Basically, I would like to allow users to FTP some files to my webserver, then I can manually run a rake task to have Paperclip process all of the files (resize the images, update the database, etc). How can I do this? ...

How to test this ==> rspec + rails

We all know that we have this code in our create action of any basic controller def create if @product.save flash[:notice] = 'Product was successfully created.' redirect_to(products_path) else flash[:notice] = "Data not saved try again" render :action => "new" end end how do we test this part of co...

How to write "First of every month in Ruby"

I'm trying to write an iterator in ruby that sends a callback on the first of every month. How would you write something like that? ...