ruby

When will a framework be available for Comet?

I wonder why it's so difficult to set up a server for live notifications with Comet. Will this ever be implemented in existing frameworks like Rails? It's popularity is huge, but it's still not easy to get it up and running. What options are there for Rails applications today? Thanks ...

How to redefine a Ruby constant without warning?

I'm running some ruby code which evals a .rb file everytime its date changes. In the file, I happen to have constant definitions, like Tau = 2 * Pi and of course they make the interpreter display the unwanted "already initialized constant" warning every time. So, I'd like to have the following functions: def_if_not_defined(:Tau, 2 * ...

Installed Phusion Passenger on Server but apache2 didn't install in /etc/apache2/

Hey all, I am following instructions on how to deploy rails application on server. I did the following: sudo gem install passenger passenger-install-apache2-module Everything is successful so far. But next on instruction he uses: nano /etc/apache2/sites-enabled/000-default Problem is there is no apache2 directory in etc. Theref...

Pretty Print HTML in Ruby (or Shell)

Is there any way to pretty print an HTML or XML string from the command line on a mac? Trying to do this in Ruby. Any ideas? I've thought about XSLT, and about writing my own parser, but both of those are pretty involved. Looking for something already out there. ...

RestClient for Ruby with smarkets.com api - Curl to RestClient

the api I'm working with is here: I'm able to log in fine and get back an auth token, but cant figure out how to do anything that requires a token. I get back a forbidden response when I try to get or post a private URL. they give an example of the request that needs to be sent using curl: curl \ --header 'Authorization: User...

why does the map.root :controller => "welcome" wont work?

Hi i have been trying to change the homepage of my app for over and hour and searched the net but cant find anything, i have map.root :controller => "welcome" set in the routes.rb file and i have deleted the index.html.erb file in public and http://0.0.0.0:3000/ still takes me to the welcome to rails default page. i have a welcome con...

Ruby kernel commands

I am trying to execute the following command in irb, exec 'gcc j.cpp' but, i got the following error: /tmp/ccYhafBj.o: In function `main': j.cpp:(.text+0x14): undefined reference to `std::cout' j.cpp:(.text+0x19): undefined reference to `std::basic_ostream >iostream> using namespace std; int main() { cout << "Hello World"; r...

Is there an easy way to define a common interface for a group of unrelated objects?

I've got a class that serializes data. I may want to serialize this data as JSON, or perhaps YAML. Can I cleanly swap YAML for JSON objects in this case? I was hoping I could do something like the following. Is it a pipe dream? FORMATS = { :json => JSON, :yaml => YAML, } def serialize(data, format) FORMATS[format].serialize(data)...

MongoMapper docs

Does anyone have a good resource for MongoMapper documentation? I've been reading through the mongoDB docs, but a lot of it doesn't convert across to ruby/mm. I've been trying to figure out how to do a SELECT FROM WHERE EXISTS with little success. db.things.find( { a : { $exists : true } } ); // return object if a is present The only ...

stdin/stdout problem in gcc + rails

...

Parse ATOM in Ruby with custom namespaces

Hi, I'm trying to read this ATOM Feed (http://ffffound.com/feed), but I'm unable to get to any of the values which are defined as part of the namespace e.g. media:content and media:thumbnail. Do I need to make the parser aware of the namespaces? Here's what I 've got: require 'rss/2.0' require 'open-uri' source = "http://ffffound.co...

give me some resources to learn ruby.

i am familiar with PHP and JSP. i am interested in learning ruby i seek some learning materials/resouces/books to learn ruby. it would be better if the material/Books/Resource compares Ruby with PHP or JSP. i prefer comparative learning. and also suggest some IDE for ruby. Thank in advance. ...

Ruby on Rails - Layout and Links

Hi All, new to Ruby so I'm still getting to grips with some of the Rails framework and how it relates. I've got a question about why my project behaves in a certain way. I've created a basic layout, header the top of screen, side menu on the left, and a contents page for the main area. Nothing flash, bog standard as you can see from th...

Ruby if Model.exists?

Have SubscriberList When an order is placed I want to check if New User's email is all ready in our subscribers list. If not, then add them. Problem is it adds them no matter what. Guess it's not performing check correctly. Currently in my orders_controller I have unless logged_in? @order.subscribe_after_purchase(@order.user.emai...

Problem with `rake test`… rake reports "Could not find task ./test/whatever-my-first-test-file-is.rb"

I've put this information into a pastie, but repeated it here (pastie link http://pastie.org/private/4vprzwhllqv35egrf8jzwg ) The problem showed up in my own project, but I have no idea what i'm doing wrong: here's the full output: $ rake test (in /Users/me/Projects/version-three) /Users/me/.rvm/rubies/ruby-1.9.2-rc2/bin/ruby -I"lib:...

Authlogic: failed_login_count not updating

I'm using Authlogic as the login system. Everything is working correctly except that it never updates the failed_login_count field when I purposely type in the wrong password. I am using the email as the login item. In the database there is no 'login' column. Is there something that I need to change or add to make this feature work? ...

Which is the most preferred language to start with dynamic languages

After working for on JAVA for a long time now i feel like also learn some other language just for a change. This time i want to spend some time learning and reading one of the dynamic languages. Which is the most appropriate one that covers most of the features offered by dynamic languages and the syntax which probably is fun and also ...

Dirty and check if email attribute changed?

Last part of my project, Hopefully. Need to check if user.email attribute changes. If it does, then need to tell mailchimp to change or add the email. Looks like Dirty will do this, but have never used it before. How can I catch the change in a block, or pass it to a block, and then update the attribute? ...

Ruby on Rails: Yield content_for Display Issues

Using 2.3.8 of rails. In the view template I have this type of code <%content_for :sidebar do %> <h2>Sidebar</h2> <p><%=link_to "somewhere", "http://www.google.com/"%&gt;&lt;/p&gt; <% end %> <h1>Pictures#new</h1> <p>Find me in app/views/pictures/new.html.erb</p> In the application.html.erb template I have <!-- END: Header --> <...

Discover the file ruby require method would load?

The require method in ruby will search the lib_path and load the first matching files found if needed. Is there anyway to print the path to the file which would be loaded. I'm looking for, ideally built-in, functionality similar to the which command in bash and hoping it can be that simple too. Thanks. ...