ruby

Rails ActionMailer view text indentation problem

When i indent code in a mailer-view, i see the indentation in the sent (plain text-)mail, too. Is there a way to avoid this without writing my code without indentation…? ...

Passenger spawning new ruby instances on Ajax calls

I have some heavy perfomance issues with Passenger and ajax calls. It seems like every time I do an ajax call, a new ruby instance is started instead of using the one that responded to the original page request, making it really slow. The fact that multiple ajax requests can be made in just a few seconds doesn't make the situation better...

What does the 't()' tag mean in ruby on rails?

I came accross an opensource code in views, with a 't()' tag similar to html escape sequence, i.e h(). <%= f.label :password, t(:password, :scope => "activerecord.attributes.user") -%> I just want to know what t() means.. Anyone? ...

what is the "sys.stdout.write()" equivalent in ruby?

as seen in python, what is the "sys.stdout.write()" equivalent in ruby? ...

undefined method `[]' for nil:NilClass (NoMethodError) Ruby

Hi Im having a problem with a project im doing through school. When I try and run my program i get this error message: undefined method `[]' for nil:NilClass (NoMethodError). I executed it through TextMate and it gave me an error and said that the instance variabel @parkin_lots not initialized?? I thought i ghad done that. Please would b...

Ruby on Rails: fixing this route to show a 404

I am working on creating a new controller/route to only allow an HTTP GET and HTTP POST. The URL should be to /foo. Naturally my route looks like the following: map.connect 'foo', :conditions => { :method => :get }, :controller => "foo", :action => "display_something" map.connect 'foo', :conditions => { :method => :post }, :c...

Opening/using a table up in Ruby

Hello, I have a simple tab-separated text file that I want Ruby to read every value in the second column and write out a text file with each table value and another number. I was wondering how might I go about doing this (probably using some kind of loop). Thanks ...

Could someone help me parse this string with regex?

I'm not very good with regex, but here's what I got (the string to parse and the regex are on this page) http://rubular.com/r/iIIYDHkwVF It just needs to match that exact test string ...

Ruby and Apache

I followed these instructions, installed passenger, but the web page is still not resolving to the ruby app. It just shows the files. Please help! http://wiki.github.com/teambox/teambox/installing-on-ubuntu ...

How to convert hash in array to array in ruby

I have array that element is hash a = [{:history_date=>"15/07/10"}, {:open_price=>"7.90"}] I want to convert to this h = {:history_date=>"15/07/10", :open_price=>"7.90"} someone please help me. ...

Rails/ActiveRecord: has_one, belongs_to and before_create

I'm having trouble figuring out how best to model my data. I have the following two models in my Rails application: class Foo < ActiveRecord::Base belongs_to :active_bar, :class_name => 'Bar' accepts_nested_attributes_for :active_bar before_create do |f| f.active_bar.foo = f # Causes stack overflow! f.active_bar.save...

What is the best aproach to build an activity log?

I need to track user activity for a new project. ...

How to completely delete and recreate thinking-sphinx index?

I am using the thinking-sphinx plugin for a ruby on rails app. In testing and development, I have reindexed many, many times, sometimes against different databases, with the result that now all of my searches return an empty array. I don't believe this is related to the codebase, because other developers using the same code can get valid...

Merging Word documents in Ruby

I have N Word documents (Office 2003) from which I want to make a single Word document by merging all the N documents together in some order. How do I go about doing this in Ruby? Thanks! It's just the documents that are created in MS Office. I do not use Windows and would prefer non-Windows solutions. EDIT: Will this be easy if the d...

change the original variable from a ruby block?

in this example: def test verb = 'nothing' yield verb puts verb end test {|verb| verb = 'something'} it will print "nothing". is it possible to change it to "something"? thanks ...

Track down memory leak in Ruby 1.9

I have a Ruby application that uses eventmachine and starts 16 processes that each manage 1000 connections. Initially each process only uses around 150MB, however after some runtime they consume more and more towards 500MB and I am running out of memory and swap. The amount of open connections (indicated by EM.connection_count) is normal...

Is it a bad idea to create worker threads in a server process?

Hello, My server process is basically an API that responds to REST requests. Some of these requests are for starting long running tasks. Is it a bad idea to do something like this? get "/crawl_the_web" do Thread.new do Crawler.new # this will take many many days to complete end end get "/status" do "going well" # this can...

Frequent "No such file or directory" while saving files via Paperclip

I feel like this will end in a facepalm moment but I've been banging on my head on it for too long. I have a Rails seed.rb file that gets all the files from a specific directory creating a new object for each file and saving the file via Paperclip: Dir["./**/*.jpg"].each do |f| ... p = Picture.new File.open(f, 'r') { |photo_file|...

ruby interview question

I got this question in a previous interview and couldnt do it , any idea? What does this do: `$=`;$_=\%!;($_)=/(.)/;$==++$|;($.,$/,$,,$\,$",$;,$^,$#,$~,$*,$:,@%)=( $!=~/(.)(.).(.)(.)(.)(.)..(.)(.)(.)..(.)......(.)/,$"),$=++;$.++;$.++; $_++;$_++;($_,$\,$,)=($~.$"."$;$/$%[$?]$_$\$,$:$%[$?]",$"&$~,$#,);$,++ ;$,++;$^|=$";`$_$\$,$/$:$;...

DateTime formatting Rails

Hi I have "Date.today + 2.days" I need to format it using .strftime, but with the "+2.days" it doesn't recognize that method.Any ideas? ...