ruby

Date and Time Conversion in Ruby

I am currently looking on converting Thu Jun 10 16:17:55 +0530 2010 to 15/06/2010 or 15-06-2010 using Ruby I am getting the dates from the DB as shown below. @tickets = Ticket.find(:all) for ticket in @tickets print ticket.created_at end I have been looking around for resources as I a n00b in RoR/Ruby. I have looked...

Good Rails tutorial on How to build an RSS Feed aggregator

I have been using Feed Zirra for some time and I like it. Now, I want to build one.. I am new to rails, Are there any good tutorials to buid RSS Feed aggregator? ...

Ruby - Manipulating Time/DateTime by the Hour/Day?

Where can I find some examples on how to manipulate the time objects by days/hours/etc? I would like to do this: time.now_by_hour #=> "Tue Jun 15 23 MST 2010" time.now_by_day #=> ""Tue Jun 15 MST 2010" time.now_by_hour - 4.weeks - 3.days #=> "Sat May 15 MST 2010" What is the recommended order of operations? The reason for this is I ...

Include a Class in another model / class / lib

I need to use function "image_path" in my lib class. I tried this (and couple of other variations): class CustomHelpers::Base include ActionView::Helpers::AssetTagHelper def self.image_url(source) abs_path = image_path(source) unless abs_path =~ /^http/ abs_path = "#{request.protocol}#{request.host_with_port}#{abs_path...

best way to receive email for multiple domains with multiple user accouts into rails app

hi all I have a cms that runs on multiple domains and therefore needs to pull emails into the app for multiple email addresses. I have setup rackspace email for a hosted email solution and am trying to find the best way to pull the emails into my app from all the mailboxes. Should i be using pop3 or imap ? should i be pulling into a ...

EventMachine occasionally fails to perform get_peername

In order to retrieve peer IP and port, you usually need to call Socket.unpack_sockaddr_in(get_peername), but I noticed that it leads to sporadic crashes because get_peername returns nil in callbacks like post_init or even in receive_data. Is that an expected behavior? If so, what callback would be the right place to save the peername in...

Why aren't c# programmers drawn to ruby as java programmers are

This is a trend I've noticed. There is a very large adoption of ruby from the java community. Is it that c# is such an awesome language + having good tools over java that most c# developers aren't as keen to switching to ruby permanently as java developers are? What are your opinions? ...

Block call in Ruby on Rails

Hi, I'm trying to clean up my code and get rid of a lot of ugly hashes. In my views I define several actions like this: @actions = { :interest => {'Show interest', link_to(..), :disabled => true}, :follow => {'Follow this case', link_to(..)} ... } As these hashes grow, the maintainability decreases. I want to convert the abov...

Running a cucumber feature multiple times

Hi, I'm trying to run a cucumber feature multiple times (i.e 500 times). Is there a way of doing this than me having to type in the same command everytime? I'm guessing this can be done using Rake? I'm not an expert in using rake or cucumber. Will appreciate your help. Thanks ...

Trouble sending html in email with Pony gem

Hi, I've found this gem to be a great and easy way to send mail but I can't seem to send any html in it. If I write the following: Pony.mail( :to => message[:to], :from => @account[:from], :subject => message[:subject], :content_type => 'text/html', :html_body => "<h1>hey there!</h1>", :via => :smtp, :smtp => { :host ...

Strange ruby syntax

Hi, what the syntax is in Action Mailer Basics rails guide ? class UserMailer < ActionMailer::Base def welcome_email(user) recipients user.email from "My Awesome Site Notifications <[email protected]>" subject "Welcome to My Awesome Site" sent_on Time.now body {:u...

Ruby SaxParser Syntax

Hi All, I found this interesting post explaining how to use saxparser for large xml files in ruby http://www.ioncannon.net/programming/643/fast-xml-parsing-with-ruby/ I would like to use the line : parser = XML::SaxParser.file("posts.xml") in one of my controllers, but instead of a file I have an xml post from another app, can anyone hel...

in Rails3 beta 4 where is the code that gets executed when you type 'rails server'?

I'm tracing my way through the source code and can't seem to find where the command "rails server" would be for a generated app. Where is it? Also is there some way I can track down these things in the future? ...

Processing Zip files in Ruby

Is anybody aware of a open source Ruby library that allows the user to process zip file entries in memory? i.e. without writing them to disk ...

How do I create spaces between every four integers in Ruby?

I am trying to take the following number: 423523420987 And convert it to this: 4235 2342 0987 It doesn't necessarily have to be an integer either. In fact, I would prefer it to be a string. ...

Set Rack session cookie expiration programatically

I'm using Rack to try to implement "Remember Me" functionality in my Sinatra app. I'm able to set the session cookie to expire when the session ends or in X seconds time but I'd like to do both. For example, if a user has clicked "remember me" then I wish for their session to end after X seconds. Eg, my app.rb has a line that looks lik...

File read fails when using Delayed Job

How to check that my params['Filedata'] is corrupted or not? I have function it's reading file from params['Filedata'] and writing it to the other file. File.open(upload_file, "wb") { |f| f.write(params['Filedata'].read) } this line working fine for me.. But when i am calling this function with delayed job function send_later than I...

Rails "Missing these required gems" error for installed gems

I know this has been asked multiple times before, but I've tried those things and still am not having any luck. For the mechanize gem, I keep getting the "Missing these required gems" error when I run db:migrate on my production server. Here's the full error: Missing these required gems: mechanize You're running: ruby 1.8.6.111...

Ruby on Rails and Domain Driven Development

Hi guys, As I know ruby on rails are using Active Record with table per class strategy. I wonder if it possible to use Rails in domain driven design style, which require ORM which has more level of abstraction of data model, such as NHibernate. Best regards, Alexey Zakharov ...

problem with ruby script/delayed_job start. delayed_job and daemon on windows.

gettting this error. pid-file for killed process 8600 found (C:/cyncabc/tmp/pids/delayed_job.pid), deleting. c:/ruby/lib/ruby/gems/1.8/gems/daemons-1.0.10/lib/daemons/daemonize.rb:103:in `fork': fork() function is unimplemented on this machine (NotImplementedError) from c:/ruby/lib/ruby/gems/1.8/gems/daemons-1.0.10/lib/da...