ruby

c# serialized JSON date to ruby

Hi guys, I have a C# application that serializes its DTOs to JSON and sends them accros the wire to be processed by Ruby. Now the format of the serialized date is like so: /Date(1250170550493+0100)/ When this hits the Ruby app I need to cast this string representation back to a date/datetime/time (whatever it is in Ruby). Any ideas h...

What is an EOFError in Ruby file !/O?

The official documentation doesn't specify. I understand EOFError means "End of file error", but what exactly does that mean? If a file reader reaches the end of a file, that doesn't sound like an error to me. ...

Problem encoding UTF8 data from Rails app to Mysql

I'm having trouble saving UTF8 data in a form and having it correctly saved in mysql. In particular, via my ruby application I'm post a form that includes the following: Gerhard Tröster Which in my terminal I see is being updated in the database as: UPDATE `xxxx` SET `updated_at` = '2009-08-13 14:22:33', `description` = '<p><s...

Are there any good Ruby FTP libraries for Ubuntu?

After spending some time on Google all that I've found so far is ChilKat which only runs on Windows. I'm looking for something similar that'll run on Ubuntu. Obviously there's NET::FTP, Net::SSH and Net::SFTP so I could roll my own and that may be what I'll do, but I'm hoping to save a lot of time by using something else that's already b...

Whats the difference between %Q and %{} in ruby?

Is there a difference? I am new to this. ...

Ruby: Search file text for a pattern and replace it with a given value?

Learning Ruby. I'm looking for a script to search a file (or list of files) for a pattern and, if found, replace that pattern with a given value. Thoughts? ...

Ruby: what does %w(array) mean?

I'm looking at the documentation for FileUtils. I'm confused by the following line: FileUtils.cp %w(cgi.rb complex.rb date.rb), '/usr/lib/ruby/1.6' What does the %w mean? Can you point me to the documentation? ...

Textile on Ruby. Restrictions? Proxies?

Can I restrict a specific "rule of conversion" from Textile markup into HTML markup? What should do to prevent such a text to be converted? p<. align left Is there a convenient way (maybe by means of Redcloth?) to create a proxy for a Textile -> Proxy -> HTML conversion? In the proxy I'd like to apply the class attribute with a specifi...

inserting and deleting nokogiri XML nodes and elements

my basic aim is to extract parts of an XML file and make a note that i extracted some part in that file (like "here something was extracted". trying around a lot with nokogiri now, it seems like not really documented on how to 1) delete all childs of a <Nokogiri::XML::Element> 2) change the inner_text of that complete element any clu...

In rails is it possible to load class layout dynamically?

I need message to have a different layout in project, is it possible in rails to do something like this? Class Messages::New < @project? ProjectLayout : NormalLayout end #i treid this, don't work, since @project has not been initiated. thanks ...

Using accepts_nested_attributes_for + mass assignment protection in Rails

Say you have this structure: class House < ActiveRecord::Base has_many :rooms accepts_nested_attributes_for :rooms attr_accessible :rooms_attributes end class Room < ActiveRecord::Base has_one :tv accepts_nested_attributes_for :tv attr_accessible :tv_attributes end class Tv belongs_to :user attr_accessible :manufactu...

Is there any command to go to the end (or beginning) of a Ruby block using vim

Hello there, Is there a way to go the end of a Ruby block using vim? For example module SomeModule # <Supposing that the cursor is HERE> def some_method end end I want to go from where the cursor is, to the end of the block with one command, is that possible? I've read this documentation, but it doesn't seem to work on .rb ...

How do i integrate Hoptoad with DelayedJob and DaemonSpawn?

I have been happily using the DelayedJob idiom: foo.send_later(:bar) This calls the method bar on the object foo in the DelayedJob process. And I've been using DaemonSpawn to kick off the DelayedJob process on my server. But... if foo throws an exception Hoptoad doesn't catch it. Is this a bug in any of these packages... or do I ne...

Ruby SOAP .. handling a soap response

Hi, I use ruby to get a report by calling a soap based web service method. By calling such a method (soap_driver.method_foo(params)) I am getting a ruby object of this type SOAP::Mapping::Object. I inspect the object and get a bunch of QNames, which I try using it to get the info out of the object. Considering the soapResponse is the ...

Rails active search with ajax and Greek letters

Hello, I'm new to programming and to Ruby on Rails, and I'm trying to implement an address book on rails with active search with ajax. Active search is working fine with English letters, but when I'm trying to search Greek entries I don't get any result. I wrote a code showing what is searching so I noticed that if I put a Greek letter...

Coming back to Rails

So I've decided after a few years away, that I want to get back into Ruby on Rails for some of my personal projects. What I'm wondering is what are the best resources to find out what the new features are in rails? I haven't really even touched Rails since 1.2 was new. Oh yeah, and is TextMate still the defacto editor for RoR on the Mac...

Automated script for Rails application creation

I'm noob with Rails. I would like to create a Rails powered website which can install automatically a Rails application (Redmine) when a user creates an account (create the application, setup user's preferences, configure the database, etc.) Each Rails application will use its own subdomain. Any idea how to do that? ...

Removing underscore character from each entry in a list of paths

hi There is an array of strings paths = ['foo/bar_baz/_sunny', bar/foo_baz/_warm', 'foo/baz/_cold', etc etc] I need to remove underscore in each last part of path (_sunny => sunny, _warm => warm, _cold => cold) paths.each do |path| path_parts = path.split('/') path_parts.last.sub!(/^_/, '') puts pat...

Rails Polymorphism 'backwards'

Say I'm writing a blog app with models for posts, pages and photos. I've got a category model, that may be linked to any of these models. So, a category may contain various kinds of items. Every item only has ONE category. I could implement this using a generic tagging pattern with a join table, but I want to make sure every subject can...

Transforming XML strcutures using Ruby

I've been wracking my brain trying to solve this problem. This is my first time using any scripting language for this kind of work, and I guess I might've picked a hard job to start with. Essentially, what I need to do is transform some basic XML into a heavier XML structure. Example : Translate the following : <xml> <test this="stuff...