This is somewhat of a broad question, but it is one that I continue to come across when programming in Ruby. I am from a largely C and Java background, where when I use a library function or method, I look at the documentation and see what it returns on error (usually in C) or which exceptions it can throw (in Java).
In Ruby, the situa...
I'm collecting all my user's email addresses for a mass mailing like this:
def self.all_email_addresses
output = ''
User.all.each{|u| output += u.email + ", " }
output
end
However, I end up with an extra ", " on the string of email addresses.
How can I get rid of this / is there a better way to get a comma separated list of...
A newbie question on Selenium for Ruby. What's the difference between "gem install selenium" and "gem install Selenium"? I'm trying to figure out which one I should install.
...
I have a SharePoint server. I am building an rails application which can interact with sharepoint server although this is not the primary goal of the application. I am planning to provide this as an advantage.
My target areas would be
1. Fetching available document repository from SharePoint
2. Add documents to sharepoint using Rails fr...
For example, if I have a user with an email address that needs validating on presense and format:
validates_presence_of :email_address, :message => "can't be blank"
validates_format_of :email_address, :with => /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i
If nothing is entered, how can I prevent both error messages appearing? I kn...
I am trying to incorporate this script here (http://snippets.dzone.com/posts/show/7530), yet i'm no ruby wizard.
Right now it pulls down mail that I want with the local_file name, but was wondering if its possible to have it pull it down and save it by the 'message subject title + date of message'. When I try using mail.date, I get a lo...
I ran sudo gem update earlier today and was thrilled to see it work, but at the end it failed.
Building native extensions. This could take a while...
ERROR: While executing gem ... (Gem::Installer::ExtensionBuildError)
ERROR: Failed to build gem native extension.
ruby extconf.rb update
can't find header files for ruby.
I don't ha...
I know of Python's list method that can consume all elements from a generator. Is there something like that available in Ruby?
I know of :
elements = []
enumerable.each {|i| elements << i}
I also know of the inject alternative. Is there some ready available method?
...
$:.unshift File.join(File.dirname(__FILE__),\
'vendor','addressable-2.1.0','lib','addressable','uri')
Does the code above access a file that has this path:
'vendor/addressable-2.1.0/lib/addressable/uri'
I'm trying to vendor the addressable gem into a Sinatra app to deploy it to my hosting provider but I keep receiving:
"no such fil...
I have a model called sites. A site will have several adjacent sites (and also be an adjacent site for other sites).
I am trying to determine how best to capture the list of adjacencies.
I have considered creating a text field in the site model and using serialize to store/retrieve the array of all of the adjacent sites. The problem wi...
I'm trying to consume some legacy XML with elements like this in JRuby:
<x-doc attr="value">
<nested>
<with.dot>content</with.dot >
</nested>
</x-doc>
I've been working with Hpricot, but Hpricot's HTML-oriented shortcuts are working against me: doc.search("//with.dot") seems to be looking for <with class="dot" />
(I ran into ...
I have found several sources regarding how to validate an xml document against a schema, but I have an application in ruby in which I need to validate that a user supplied schema is a valid schema itself. Is there a way to that I can check this? Is there an XSD schema to validate an XSD schema? Or are there libraries or gems that do t...
I am teaching myself rails (coming from PHP for web apps) and I can't find any good docs to help me. But I was wondering how would you tell your method to take the last post(controller is post) in the database? I tried Post.find(:last) but that did nothing sadly. Anyone know?
...
I have rake task to seed the application with random data using the faker gem. However, we also have images (like logos) that we want uploaded in this rake task.
We already have Paperclip set up, but don't have a way to upload them programmatically in a rake task. Any ideas?
...
Hi There,
I want to derive from a c++ class in ruby and then pass an instance back to a c++ call. Specifically I want to derive from Xapian::Weight (http://xapian.org/docs/apidoc/html/classXapian%5F1%5F1Weight.html) and then tell Xapian to use my implemention.
I have Xapian talking correctly with acts_as_xapian, but can't get to accept...
I have a div called #output, styled with overflow: scroll;. Using jQuery.ajax, it's being updated every x second. I'd like to have it so that when the scrollbar appears (after the divs filled up), it should continously stay at the bottom of the div instead of the top, like most chat clients do.
I'm sure there's a way to do this, I just ...
This is the snippet of code i'm using now:
def countOccurences(a, b)
#counts the number of occurences of a in b
count=0
cur=0
while cur < b.length do
temp=b.index(a, cur)
if temp == nil
break
end
count=count+1
cur=temp+a.length
end
return count
end
Is there any Ruby function that does this? Any f...
I want to find the fastest logger Ruby has to offer. My intuition tells me that syslog would win in this race. But my intuition seems to be wrong. Syslog turns out to be the slowest out of the three loggers I've tested. I'm using my MacBook Pro, OSX 10.6 (Snow Leopard), Intel Core2 Duo, 4GB of RAM and Ruby 1.8.7 built from MacPorts. ...
I have a class like so:
class Item
attr_accessor :item_id, :name, :address, :description, :facilities, :ratings, :directions, :geo, :images, :video, :availability
def self.create options={}
item = Item.new
item.item_id = options[:item_id]
item.name = options[:name]
item.description = options[:desc]
item.ratings ...
I want to test how priorities are working in the delayed_job plugin. Im using the mailit app from railscasts. I think i want to send 100 messages with a high priority and 100 with a lower priority. And i want to see if the messages with a lower priority will be delivered on time or they will be put aside.
How can i do a test like this....