I'm developing a real estate web catalogue and want to geocode every ad using geokit gem.
My question is what would be the best database layout from the performance point if i want to make search by country, city of the selected country, administrative area or nearest metro station of the selected city. Available countries, cities, admin...
so lets say i have a pre existing directories /source/version/1 , /source/version/2, /source/version/3
I want to monitor if there is a NEW directory created /source/version/4, and send an email if such directory is indeed created.
...
Are there any good examples/plugins that enable users to create groups within a community application. For example, I would like to create a Group class and add it to something like Community Engine (http://communityengine.org/). Essentially, users need to be able to create and manage groups that other users can join (much like Facebook ...
I'm using mongo_mapper 0.7.5 and rails 2.3.8, and I have an instance method that works in my console, but not in the controller of my actual app. I have no idea why this is.
#controller
if @friendship.save
user1.add_friend(user2)
...
#model
...
key :friends_count, Integer, :default => 0
key :followers_count, Integer, :default => 0
...
Let's say I have a function
def odd_or_even n
if n%2 == 0
return :even
else
return :odd
end
end
And I had a simple enumerable array
simple = [1,2,3,4,5]
And I ran it through map, with my function, using a do-end block:
simple.map do
|n| odd_or_even(n)
end
# => [:odd,:even,:odd,:even,:odd]
How could I do this with...
I'm running Sinatra 1.0 with HAML, my form has a number of checkboxes, for example books I like, and you would select all the books you want. The checkbox name is "books".
In sinatra params['books'] there should be an array of all the books that were checked, but it only has the last item that was checked, not an array.
How can I get a...
I can't seem to find this and I feel like it should be easy. In Ruby on Rails, how do I take:
2010-06-14 19:01:00 UTC
and turn it into
June 14th, 2010
Can I not just use a helper in the view?
...
Hi,
Which of these two forms of Array Initialization is better in Ruby?
Method 1:
DAYS_IN_A_WEEK = (0..6).to_a
HOURS_IN_A_DAY = (0..23).to_a
@data = Array.new(DAYS_IN_A_WEEK.size).map!{ Array.new(HOURS_IN_A_DAY.size) }
DAYS_IN_A_WEEK.each do |day|
HOURS_IN_A_DAY.each do |hour|
@data[day][hour] = 'something'
end
end
Method ...
This was a homework assignment for my students (I am a teaching assistant) in c and I am trying to learn Ruby, so I thought I would code it up. The goal is to read integers from a redirected file and print some simple information. The first line in the file is the number of elements, and then each integer resides on its own line.
This...
Hi there, I've used antlr and javacc/freecc for a while.
Now I need to write a bunch of parsers using antlr grammars but such parsers need to be written in ruby lang.
I googled but nothing found. Is there any ruby parser generator that takes antlr grammars and create a parser? If there are many, which is the best one in your opinion?
T...
I'm running an import script which imports a CSV dump of a database into a local sqlite database using DataMapper.
My models look like this:
class Staff
include DataMapper::Resource
property :staff_id, String, :key => true
property :full_name, String
end
class Project
include DataMapper::Resource
property :pro...
Is there a way I could retrieve created_at value from the Database in Rails?
The table has columns like ticket_created, ticket_updated. By default a created_at column is also included. If I try doing:
@tickets = Ticket.find(:all)
for ticket in @tickets
puts ticket.created_at
end
the above code is returning ticket_created i...
I'm trying to make has_many relation with dynamic class_name attribute
class Category < ActiveRecord::Base
has_many :ads, :class_name => ( lambda { return self.item_type } )
end
or
class Category < ActiveRecord::Base
has_many :ads, :class_name => self.item_type
end
But i got errors:
can't convert Proc into String
or
undefi...
According to the documentation: "Mechanize lets you access form input fields in a few different ways". But I can only see one way using accessors.
What other options are there? For example: can you reference form field parts like "Mechanize::Form::Text:0x101698168" instead of having to use the name value.
...
Does anyone knows how to force WEBrick to process more than one request at a time? I'm using some Ajax on my page for long running database-related tasks and I can clearly see the requests are being processed in a pipeline.
...
I want to use the value v inside of an instance method on the metaclass of a particular object:
v = ParserMap[kind][:validation] # We want to use this value later.
s = ParserMap[kind][:specs]
const_set(name, lambda {
p = Parser.new(&s)
# This line starts a new scope...
class << p
define_method :validate do |opts|
v.ca...
I've got two models: Item and Tag. Both have a name attribute. I want to find items tagged with several tags.
class Item < ActiveRecord::Base
has_many :tags
validates_presence_of :name
end
class Tag < ActiveRecord::Base
belongs_to :item
validates_presence_of :name
end
Given a list of tag ids, I can easily enough get the list ...
Is there a way to require a gem and then get the version number of that gem from within ruby?
...
I'm running Ruby 1.8.7 with Rails 2.3.5 on Ubuntu 10.04 64-bit. I've written a method that should take a string like this, "École À la Découverte" and output a file-system name like this "ecole_a_la_decouverte":
(Iconv.new('US-ASCII//TRANSLIT', 'utf-8').iconv "École À la Découverte").downcase.split.join('_')
When I test this line in m...
My question is similar to this one http://stackoverflow.com/questions/1342761/how-to-skip-activerecord-callbacks but instead of AR I'm using Mongoid, It seems like that isn't implemented yet in the current version of Mongoid, so I'd like to know what should be an elegant solution to implement it. (if necessary).
...