Rails: find out if an IP is within a range of IPs
This is a tricky one... How can you tell if an ip, say 62.156.244.13 is within the range of 62.0.0.0 and 62.255.255.255 Is there a simple Ruby way to do this, or how can I solve this? ...
This is a tricky one... How can you tell if an ip, say 62.156.244.13 is within the range of 62.0.0.0 and 62.255.255.255 Is there a simple Ruby way to do this, or how can I solve this? ...
I would like to do something like this from a Ruby script, within a loop: Write a file a.rb (which changes each iteration) execute system(ruby 'a.rb') a.rb writes a string with results to a file 'results' a.rb finishes and Ruby returns 'true' (assuming no errors) the calling script reads the file 'results' and takes action. I expect ...
Im trying to code my own DSL for file manipulation, just for the sake of learning. My goal is to make it understandable and easy to code. Here are 3 alternatives for appending a string to a database.yml: 1. append("windows").to("database.yml") 2. append(string: "windows").to(file: "database.yml") 3. append_string("windows").to_file(...
Possible Duplicate: How do I use define_method to create class methods? I am trying to do this: class Foo class << self def runtime_method(*methods) methods.each do |name| define_method "self.#{name}" do |*args| "dynamic class method #{name.inspect}" end self.class_eval do ...
In rails3, almost all query interface change to be lazyloading now, but 'will_paginate' will hit the database imediately after you use the 'paginate' method. How can I make it lazyload records? ...
I want to parse an html file using nokogiri ...I am able to do that but i only want text and no cdata ot javascript ...since my js and divs are all over th file ..please offer a gud solution ...
I'm trying to get started with Twilio's REST API using the rubygem twilio-ruby, and I've hit a snag. Here's my code: h = {:From => "123-123-1234", :To => "123-123-1234", :Body => "hey"} account = Twilio::RestAccount.new(ACCOUNT_SID, ACCOUNT_TOKEN) resp = account.request("/#{API_VERSION}/Accounts/#{ACCOUNT_SID}/SMS/Messages", 'POST', h) ...
I'm dynamically defining a module name from an argument passed on the cli, for example "Required::Module::#{ARGV.first}" Is there any way to check if that module exists? Also, how would I run methods on it not knowing it's exact name? ...
I've trying to get the flickr-fu gem to search correctly only for commercial friendly photos but with no luck. It seems to ignore the parameter altogether. photos = flickr.photos.search(:text => "anything", :tags => 'architecture', #:license_id => '4,6,5', ...
I want to get the index as well as the results of a scan "abab".scan(/a/) I would like to have not only => ["a", "a"] but also the index of those matches [1, 3] any suggestion? ...
I've xcode 3.0 installed. And I need to install sqlite3-ruby gem (for rhosync). When I run: sudo gem install -l sqlite3-ruby I get following error: Building native extensions. This could take a while... ERROR: Error installing sqlite3-ruby: ERROR: Failed to build gem native extension. /System/Library/Frameworks/Ruby.framework/V...
Hi guys, I'm trying to adopt Jammit in my Rails application. Default config provided in documentation grabs all js files including view specific javascript: embed_assets: on javascripts: workspace: - public/javascripts/vendor/jquery.js - public/javascripts/lib/*.js - public/javascripts/views/**/*.js - app/views/work...
Dear all, I am a Selenium (Ruby) newbie. I am trying to launch google homepage as below: @selenium = Selenium::SeleniumDriver.new("localhost", 4444, "*firefox", "http://www.google.com", 10000); @selenium.start However, after the script runs, it launches firefox with below URL: http://localhost:4444/selenium-server/core/Blank.html?st...
I'm a beginner at rails. And I've come to understand two different ways to return the same result. What is the difference between these two? And what situation would require you to choose one from the other? Example 1: Object.find(:all).select {|c| c.name == "Foobar" }.size Example 2: Object.count(:conditions => ['name = ?', 'Fooba...
any suggestions on how to use activemerchant with discount codes where cart total can = $0.00 ...
I am making a select box, and I'm using a collection in it. But at the top of all the selections I want to add something that otherwise wouldn't be in that collection. Here is my select box : = select (@organization, "tabs", @organization.tabs.collect { |t| [t.title, t.id] }, {}, {:class => "text_tab_link"} ) And I would like to ad...
What's the best idiomatic (cleanest) way to convert an array of strings into a string, while keeping the enclosing quotes for each elements. In other words, from this: a = ["file 1.txt", "file 2.txt", "file 3.txt"] I'd need to get this "'file 1.txt' 'file 2.txt' 'file 3.txt'" Single and double quotes could be interchanged here. The...
I have installed a plugin to my Rails app. The plugin has files in its public directory that I want to make available. For example, vendor/plugins/myplugin/public/javascripts/myplugin.js. Can I make this available via Rails at /javascripts/myplugin.js? I've got it working by copying the files from vendor/plugins/__/public/* to public/...
class Foo include Module.new { class_eval "def lab; puts 'm' end" } def lab super puts 'c' end end Foo.new.lab #=> m c ======================================================================== class Foo include Module.new { instance_eval "def lab; puts 'm' end" } def lab super puts 'c' ...
What technique does a ruby script use to find your libraries / requires on Windows. I have an install of Ruby 1.8.7 on Windows to the path C:\Ruby187 and non of my "requires" work. For example, just a test file require "rack" gives no such file to load -- rack (LoadError) gem list rack is there ...