Ruby gsub : is there a better way
I need to remove all leading and trailing non-numeric characters. This is what I came up with. Is there a better implementation. puts s.gsub(/^\D+/,'').gsub(/\D+$/,'') ...
I need to remove all leading and trailing non-numeric characters. This is what I came up with. Is there a better implementation. puts s.gsub(/^\D+/,'').gsub(/\D+$/,'') ...
I'm starting to use vlad for new deployments and am wondering what's the best way to set it up so I can use the same tasks for my local development and remote production servers? I thought about defining everything as remote tasks then having dev/prod methods which set the domain variable, then I can just call rake dev/prod vlad:do_some...
I want to my controller in my app to not just respond to the id of the object sent from it's route, but actually a sha1 hash, i've generated using Digest::SHA1.hexdigest. So instead of: /client/invoice/1 I want the url to be something like: /client/invoice/0beec7b5ea3f0fdbc95d0 ...
I'm new to Ruby, coming primarily from C# and ActionScript 3 (among other langauges). I'm curious about abstracting functionality. Specifically, wrapping and abstracting Ruby's FTP and SFTP libs. I was searching around and came across a gem called Backup. It really got my attention because it supports backing stuff up via S3, SCP, SF...
I'm writing an extension for Spree and I want to remove an existing association. Given the following code: class Project < ActiveRecord::Base has_one :status ... end How can I remove the call to has_one :status at runtime? I want to remove the association and associated methods. ...
I'm in the middle of trying to upgrade a rails project from rails 2.0.2 to rails 2.3.5 In doing so, I've noticed a change that is driving me nuts. It seems that now by default, any queries that are run by the application get logged to the webrick console (I'm working in Eclipse/Aptana). It used to be that webrick would only show request...
I am trying to dynamically create a class using the eval method. It is working fine except for one small problem. As my code shows I am creating the Browser class inside the BrowserFactory class. When I do this the Browser class has an added namespace of BrowserFactory. Is there anyway to evaluate the Browser class from a string with...
Model: Product has-many product-categories, :through => ... Question 1) How do I index a many to many association with thinking sphinx Must I use has? Questions 2) How is this searched in the controller ex. Product.search params[:search-params], :conditions => {some_conditions} ...
I created a feature that requires two folders to work correctly. These folders didn't existed in the rails project so I had to create them. Now I need to push this functionality so that the other developers can use it as well. What do you think is the best practice: Create the folders locally and leave a note somewhere explaining that...
Hi All I've got a problem trying to install the Ruby mysql gem driver. I recently upgraded to Snow Leopard and did the Hivelogic manual install of MySQL. This all seems to work fine as I can access mysql from the command line and make changes to the database. My problem is that if I now use rake db:migrate I get: rake aborted! uni...
I'm attempting to use the selenium-webdriver [ruby bindings][1] to access an internal web-site that requires a proxy to be configured, and HTTP Basic Auth. I currently have: require "selenium-webdriver" driver = Selenium::WebDriver.for :firefox driver.navigate.to "http://my-internal-site.com" But this fails due to both the pro...
I use Authlogic for authentication in my Rails project. It provide default validation for email and login field. But, I want to allow email to be null for join because my service is for mobile and it is difficult to insert email field in mobile device. How can I skip email validation with Authlogic in Rails? ...
I am trying to build an XML document using Nokogiri. Some of the elements have hyphens in them. To illustrate the problem is an example: require "nokogiri" builder = Nokogiri::XML::Builder.new do |xml| xml.foo_bar "hello" end puts builder.to_xml Produces: <?xml version="1.0"?> <foo_bar>hello</foo_bar> However, when I try: build...
I installed Netbeans IDE 6.8 today to use it while learning Ruby. Here the specifications: Product Version: NetBeans IDE 6.8 (Build 200912041610) Java: 1.6.0_17; Java HotSpot(TM) Client VM 14.3-b01 System: Windows XP version 5.1 running on x86; Cp1252; en_US (nb) So I created my first Ruby project and am able to run...
We have pretty big (~200mb) xml files from different sources that we want to transform into a common format. For structural transformations (element names, nesting, etc) we decided to use XSLT (1.0). Because it has to be fast (we receive a lot of those files), we chose Apache Xalan as the engine. Structural transformations might be qui...
Watir's site says I need Ruby 1.8.6, which I'm running. And windows installation should be as simple as gem install watir. But when I run that, I get this: C:\Users\Ryguy\Code>gem install watir Building native extensions. This could take a while... ERROR: Error installing watir: ERROR: Failed to build gem native extension. C:...
So I have the following code that reads a text file line by line. Each line ends with a return carriage. The code below outputs the following: define host { use servers host_name ["buffy"] alias ["buffy"] address ["buffy"].mydomain.com } How do i get rid of the bracket and quotes? File.ope...
I am getting Encoding::UndefinedConversionError at /find/Wrocław "\xC5" from ASCII-8BIT to UTF-8 For some mysterious reason sinatra is passing the string as ASCII instead of UTF-8 as it should. I have found some kind of ugly workaround... I don't know why Rack assumes the encoding is ASCII-8BIT ... anyway, a way is to use string.forc...
I'm considering using Integrity as a continuous integration tool, but don't want to (or can't) set up a separate domain for the application. Is it possible to get a Sinatra app (like integrity), and make it a Rails Engine? How would one go about do it? EDIT: I realize that the "engines" normally require Rails code like controllers a...
How would I Start and stop a separate thread from within another thread? loop_a_stopped = true loop_a = Thread.new do loop do Thread.stop if loop_a_stopped # Do stuff sleep 3 end end loop_b = Thread.new do loop do response = ask("> ") case response.strip.downcase when "s...