ruby

What is a better way to convert a simple sinatra app to static html pages?

A friend of mine asked to create a static website and I found that making such site using Sinatra is a pure joy. I just wrote all my routes like this: get '/index.html' do haml :index end get '/app.css' do sass :app end .... So I was able to use layouts, and haml and sass to put site together quickly. To create the static site ...

Does ActiveRecord make Ruby on Rails code hard to test?

I've spent most of my time in statically typed languages (primarily C#). I have some bad experiences with the Active Record pattern and unit testing, because of the static methods and the mix of entities and data access code. Since the Ruby community probably is the most test driven of the communities out there, and the Rails ActiveReco...

Rails debugging rails tasks

Hello. How is it possible to debug rake tasks? When I write debugger it does not start: NoMethodError: undefined method `run_init_script' for Debugger:Module from /usr/local/lib/ruby/gems/1.8/gems/ruby-debug-base-0.10.3/lib/ruby-debug-base.rb:239:in `debugger' from (irb):4 If I run rake my:task --debugger rake returns me to console i...

Ruby on Rails: building a model with an attribute not in the database?

I have a model that sets one of its attributes based off of a form parameter that a user submits. The model is a child resource to a parent resource Home. A hypothetical example is the following: A class Person has an age attribute. The user submits a birthdate as an HTTP POST parameter and from that, I need to derive the age of the use...

Re-Include Module

Hello, I need some like this: module One def test; puts 'Test One'; end end module Two def test; puts 'Test Two'; end end class Foo include One include Two include One end In this case I need as a result 'Test One' but obviously it returns 'Test Two'. I need a clean simple way for re-include my module. Any suggestion? ...

Jruby Gems-in-a-jar issue

Hi all, I am trying to write some code in ruby (using jruby) to be compiled to java bytecode with jrubyc and deployed to a remote machine where it will be run on the JVM (no ruby available there). Everything works fine as long as I am happy to stick with the standard jruby library. As explained on the jruby website, I simply copy the jr...

Could MacRuby / HotCocoa supplant the need to know Objective-C?

I just discovered MacRuby / HotCocoa and really like the sound of what they're doing. I had essentially discounted the prospect of making Cocoa GUI applications myself because I have an aversion to spending time & effort learning yet another C-based language, Objective-C. I'm not saying it's bad, just not for me. Is it the case now, or...

rails add :prompt to form_tag fields?

Hey guys, My question is simple. Can I add either of the blow :prompt => "Any" :include_blank => true to a form in form_tag. Here is an example. I would like to add :prompt to the select_tag :condition and select_tag :category fields and am having trouble. <ul id="homepage_searchbar"> <% form_tag junklists_path, :method => :get do...

Ruby on Rails check box not updating on form submission

I have an entries controller that allows users to add contact information the website. The user-submitted information isn't visible to users until the administrator checks a check box and submits the form. So basically my problem is that if I check the check box as an administrator while initially creating an entry (entries#new) the entr...

Parsing a CSV File to a Rails Database

G'day guys, I'm using fasterCSV and a rake script to parse a csv with about 30 columns into my rails db for a 'Trade' item. The script works fine when all of the values are set to strings, but when I change it to a decimal, int or other value, everything goes to hell. Wondering if fasterCSV has built in int etc parsing or whether I'll ...

Any reccomendations for implementing a user-defined workflow in Ruby?

I'm interested in creating a system where the user can define the steps in a workflow. Is there a gem that already handles this? I thought about one of the state machine gems, but they all seem to be for pre-defined states. I've been thinking maybe i can use state machine for the individual step types... An email step could have a few st...

How to Iterate in ruby ?

Hi I would like to iterate @some_value outputs the following result {"Meta"=>{"Query"=>"java", "ResultOffset"=>"1", "NumResults"=>"1", "TotalResults"=>"21931"}} i need to retrieve the Value of each individual value for example java 1 1 21931 ...

fastercsv parsing to int or other into ActiveRecord

I'm currently importing a CSV into an activerecord element but can't choose to parse the elements as say ints or decimals on a case by case basis using fastercsv. I can either choose to parse everything as an int or the other, or all as strings. I need to parse some columns as ints, some as decimals and some as strings. Otherwise, is th...

Regular expression for matching words between <blockquote> & </blockquote>

Basically I want to strip the document of words between blockquotes. I'm a regular expression newb and even after using rubular, I'm no closer to the answer. Any help is appreciated. ...

How can I synchronize multiple Workling workers?

I have the following situation: Three tasks: A,B,C (Implemented as Workling workers) Two user events (Calls of a controller method) The tasks are triggered this way: The first user event triggers Task A and Task B. Then an optional user event can trigger Task C, but that task must not run until Task A and B are finished. How can ...

Using a locale-dependent sorting function in Ruby/Rails

What is a good approach to sorting an array of strings in accordance with the current locale? For example the standard Array#sort puts "Ä" after "Z", which is not correct in German. I would have expected the gem I18n to offer a hook for defining my own sorting algorithms or providing collation strings or objects. In my imagination, pas...

Background process in linux using Ruby on Rails

Hi All, I want to do some process such as sending emails or using ffmpeg commands in backgound as it takes to much time. I want it should run in a background. I am using Fedora 10. Also can i check whether my background process is running successfully or not . is it posssible?if yes what would be the steps i should follow.Any help is a...

Parsing to a total DateTime object in Rails

I'm currently given three values in a table A date value in the format of %dd-%mname-%yy (i.e 06-may-05), and am parsing that using Date.parse(input,true) to fix the issue with the leading values. I'm then given a time value in the form of %hh:%mm:%ss.%ms (the ms of which I can take or leave) and a third value of a GMT offset. I can't...

Extra arguments for Factory Girl

I need to pass extra arguments to factory girl to be used in a callback. Something like this (but more complex really): Factory.define :blog do |blog| blog.name "Blah" blog.after_create do |blog| blog.posts += sample_posts blog.save! end end and then create it with something like this: Factory.create(:blog, :sample_pos...

PostgreSQL activerecord weirdness for .maximum

I have an ActiveRecord before_save method throwing an odd error: class MyThing < ActiveRecord::Base before_save :dostuff def dostuff p self.class.maximum(:mycolumn) end end When I was using SQLite this worked perfectly, now—with postgresql—I get the error: PGError: ERROR: current transaction is aborted, commands ignored un...