ruby

Format nested hashes to strings in Ruby

I would like to parse data and get in output: arg = "sth" format(arg) # => { "event[actor]" => "sth" } arg = {:a => "sth", :b => { :c => "sth else", :d => "trololo" }} format(arg) # => { "event[actor][a]" => "sth", "event[actor][b][c]" => "sth else", "event[actor][b][d]" => "trololo" } How to do that? ...

Update object array values in rails view.

I have @table_name(object array) contain many objects. I want to replace its column values one by one with my values.. i have use <% for group_permission in @table_name %> <%end%> How i change Please help me ...

How do i parse columns in a CSV File in Ruby and store it as an array

lets say we have the following csv file: Date,Av,Sec,128,440,1024,Mixed,,rule,sn,version 6/30/2010,3.40,343,352.0,1245.8,3471.1,650.7,Mbps,on,s-2.8.6-38,4.9.1-229,,vs. 342,-0.26%,-0.91%,1.51%,-0.97% 6/24/2010,3.40,342,352.9,1257.2,3419.5,657.1,Mbps,on,s-2.8.6-38,4.9.1-229,,vs. 341,0.23%,0.50%,-1.34%,0.67% 6/17/2010,3.40,341,352.1,1251....

Automatically deleting objects older than n days in Amazon S3 (How ?)

I am storing many images in Amazon S3, using a ruby lib (http://amazon.rubyforge.org/) I don't care the photos older than 1 week, then to free the space in S3 I have to delete those photos. I know there is a method to delete the object in a certain bucket: S3Object.delete 'photo-1.jpg', 'photos' Is there a way to automatically delet...

rubyon rails, rake, crontab and encoding

I have a rails rake task which runs just fine. I want this task to be run periodically by crontab so I added it to crontab as follows : 0,30,0 * * * * cd /var/www/html/metajorn && RAILS_ENV=production /usr/local/bin/rake myraketask --trace >> /var/www/html/metajorn/log/cron_log.log 2>&1 In cron_log.log I'm seeing the following error...

Rails Workflow::create_workflow_diagram options

What are all the options available for the command: Workflow::create_workflow_diagram(klass, dir, opts) and how shall I specify them on Ruby code? I've already found this on graphviz options, but I don't know how to use these options on Ruby code... Thank you all! ...

Why do you love Ruby, [Other programming language]?

I've reached the point of burnout and I haven't even started my career. Whenever I look at C it looks nice and light and just clean until I start writing anything in it. C++ is just plain and simply ugly, I won't even say anything about PHP, Lua and Python kinda ok but quickly gets to the point where I just can't enjoy writing anything i...

How do i test user input from the gets method in ruby?

Say I have the following method: #Create new guest object. Add it to array and save it to disc def new_guest printf "First name: " first_name = gets.chomp printf "Last name: " last_name = gets.chomp printf "Adress: " adress = gets.chomp printf "Phone:" phone = gets.chomp new_guest = Guest.new(first_...

Are annotations some sort of DSL in Java?

After a bunch of XML config files, I've seen Java moving to Annotation based configurations. Are annotations playing the role of DSL here? Is it because the static nature of Java? I'm thinking in Ruby which doesn't have ( afaik ) things like that. Is it because Ruby has good metaprogramming capabilities? Are there alternatives ( I m...

MySQL + Snow Leopard + 32 Bit + Ruby on Rails = uninitialized constant MysqlCompat::MysqlRes (HELP!)

So i'm running Snow Leopard on a BlackBook. I'm attempting to get rake db:migrate to work with this project but I get the MysqlCompat::MysqlRes error. Is there any special way to install or build the gem and/or the actual MySQL binaries themselves to get this to work on my machine? ...

Ruby MongoMapper Question about Mapping

I have a MongoDb database called Northwind. The database was created using C# driver. It contains 10-20 rows. Now, I want to get all those rows out from Ruby. I am using MongoMapper but how can I map a Ruby class "Category" to the "Name" field in the document. require 'mongo_mapper' class Category include MongoMapper::Document key :...

Regular expression - excluding a character

Here is an example: s="[email protected]" s.match(/+[^@]*/) Result => "+subtext" The thing is, i do not want to include "+" in there. I want the result to be "subtext", with out the + ...

RoutingError on Ruby Rails?

Hey everyone, thanks for reading this. Ihave the next issue: When I call my "New" template (generated by scaffold) I got the next error: <h1>ActionController::RoutingError in Flujos_de_trabajo#new</h1> Showing app/views/flujos_de_trabajo/new.html.erb where line #3 raised: flujos_de_trabajo_url failed to generate from {:controller=>"f...

Rails: calling yield in a partial template?

I see this sometimes in a partial erb template: <%= yield :someval %> Other times there is no yield at all. What's the advantage of calling yield in a partial? ...

Best cross-platform GUI and USB language

I am interested in developing a cross-platform application (mostly for Windows and Mac, Linux not so much) that will need a somewhat, but not overly, complex GUI (displays of graphed data) and will also have to receive input from an external controller via USB. I am interested what languages or combinations of languages (or frameworks, o...

Ruby on Rails: How do you seed the *_type column in polymorphic models?

I have a lot of data that I'm trying to seed into a polymorphic model in Rails 2.3.8. The association for all of the data is with the County model. The data looks like: data = Datum.create([ ... { :value => '14389', :value_type => County, :value_id =>'3103'}, { :value => '59013', :value_type => County, :value_id =>'3105'}, { :va...

Problem using OpenStruct with ERB

EDIT: forgot to include my environment info... Win7x64, RubyInstaller Ruby v1.9.1-p378 EDIT 2: just updated to v1.9.1, patch 429, and still getting this same error. Edit 3: running this same code in Ruby v1.8.7, patch 249, works fine. so it's v1.9.1 that broke it, apparently. I'm new to using ERB and the samples i could find are... um...

Compiling openssl with ruby on windows

Hello, i am trying to compile openssl with my ruby config on a windows computer with MingW. I am running ruby 1.9.2rc2 with these commands: $ ruby extconf.rb --with-openssl-dir=/c/openssl ... ... ... === Checking done. === creating extconf.h creating Makefile Done. Okay, so that works without any errors. Let's try to make: $ make gcc...

Is it better to learn ruby before learning rails?

Possible Duplicates: Do I need to know Ruby in order to learn Ruby on Rails? Should I start with Ruby or Ruby On Rails? I'm going to start playing with ruby, is it better to learn the ruby language alone or at the same time as learning rails? ...

Get the time corresponding to the start of the current calendar month

How can I get a Time object corresponding to the start of the current calendar month? E.g., if I ran the function today I'd get a Time object for 7/1/2010 at midnight Bonus question: How can I do the same thing for the current week? If I ran this function today I'd get a Time object for 7/11/2010 at midnight ...