deleting multiple key and value pair from hash in rails
hi i have a hash like number = {:a => 1,:b => 2, :d => 3, :d =>4} upon evaluation of certain condition i want to delete key n value pair of a,b,c Thanks in advance ...
hi i have a hash like number = {:a => 1,:b => 2, :d => 3, :d =>4} upon evaluation of certain condition i want to delete key n value pair of a,b,c Thanks in advance ...
Im trying to make my rails application (2.3.5) to run on Ruby 1.9, I've this function that make some transformations on a string: def replace_special_chars(downcase = true) if downcase string = self.downcase else string = self end string.gsub! /á|ã|à|ä|â/, 'a' string.gsub! /é|è|ë|ê/, 'e' string.gsub! /í|ì|ï|î/, 'i' string.gsub! /ó|...
I have an array of objects @objects and would like to split this into an array of arrays based on a parameter, ending up with an array where each entry is an array of objects all of which have object.property the same. @objects = [obj1, obj2, obj3, obj4, obj5] obj1.property = a obj2.property = a obj3.property = b obj4.property = b obj...
I am trying to play with redis on my Ubuntu machine and my little script doesn't work. I have installed redis gem and tried this little script (I know its pretty small) require 'redis' redis = Redis.new I get this error : ./redis.rb:4: uninitialized constant Redis (NameError) from redis.rb:2:in `require' from redis.rb:2 when I com...
I am happy enough using virtual attributes on a Rails models if they are strings, but I would also like to use other types of attribute, like dates or booleans, so that I can use helpers like date_select to set virtual attributes. Is there a nice way of doing this? As it stands, using a date_select helper on a virtual attribute raises:...
This is one of the most difficult things to search for because when you search how to parse a regex you get how to parse with a regex. I want to read a regex from a file, put it in an object somehow, then parse strings using that regex in my program. Im sure someone has done this before, can you help me out on where to start? ...
I have a compiled Python library and API docs that I would like to use from Ruby. Is it possible to load a Python library, instantiate a class defined in it and call methods on that object from Ruby? ...
Hey guys There is a lot of demand in my country for rails and hosting, yet there is not one provider that does this. Are there packaged solutions, or at least guides, out there that can help me get started with providing hosting to people? You can think of it as a local Heroku.com ...
I want the following module to be included in a class I have: module InheritanceEnumerator def self.included(klass) klass.instance_eval do instance_variable_set('@subclasses',[]) def self.subclasses @subclasses end original_method = self.respond_to?(:inherited) ? self.pub...
i'm trying to have the following structure get /something/id/apply => controller 1 post /something/id/apply => controller 2 is there an easy way to accomplish this in rails 2.x? right now i'm resorting to manually checking the http method in the controller code, and that seems... fugly. ...
When I run my app I get this error: config.gem: Unpacked gem rakismet-0.3.6 in vendor/gems has no specification file. Run 'rake gems:refresh_specs' to fix this. And when I run: rake gems:refresh_specs I get: No Rakefile found I've tried the rake command from various directories within the application hierarchy with no success....
First of all, it doesn't seem that the DateTime format variables are documented anywhere so a +1 to anyone who can show this to me in rubydocs. Second of all, when looking at the Date.strftime function code, I don't see anything that can let me do something like: Thursday, September 9th 2010 Does anyone know if this is possible? ...
I'm trying to write a function that would apply the function to just one item if it's not a collection, or else apply that function to each of the collections elements. For example: replace spaces with underscores foo 'a bear' => 'a_bear' foo ['a bear', 'a bee'] => ['a_bear', 'a_bee'] Is this possible? ...
I'm doing a simple Net:LDAP search and when I'm outputting an entry's attribute that may not exist for every entry, I get an error "NoMethodError: undefined method 'some_attribute'" Here is the code: require 'rubygems' require 'net/ldap' ldap = Net::LDAP.new ldap.host = 'ldap.example.com' ldap.port = 389 if ldap.bind filter = Net::L...
I’m a beginner in Ruby, so I’m sorry to ask something so simple, but is there anything wrong with this code – 3.upto(9) { print "Hello" puts " World" } or 3.upto(9) { |n| print "Hello " puts n } It works well enough, but most of the code samples I see use the syntax of 3.upto(9) do |n| print "Hello " puts n end is ...
I am new to Rails. I came from a Codeigniter background. I am having a hard time finding resources on Rails 3.0 for beginners. I read my new Rails book but am still confused about a few things. How do I include my libraries or helpers into a controller? Do I use an "include" or "require"? The 2nd question is how do I dynamically load p...
The page http://www.ruby-lang.org/en/downloads/ only says 1.9.1 for Linux. Right now I am using RVM to do an rvm install 1.9.2 and it needs compilation. There is no apt-get install way to install it? Is there a way to list all Ruby version apt-get can install? ...
After a recent reinstallation of Ubuntu, I reinstalled RubyGems. The Ubuntu repository grabbed version 1.3.5. Later I found I need the latest version. So I installed the RubyGems update to get to version 1.3.7. The trouble is, upon upgrading gem list returns only a small subset of all my originally installed gems. In the past, I've ...
My Scenario: Sessions are being stored in the database using ActiveRecord::SessionStore User is on site at 'http://domain.com ' they go to secure checkout at 'https://domain.secure.com' (our app has lots of domains, but want to send everyone through secure checkout on the same domain to save SSL headaches). We append session_id and a h...
Hi all, Have a nested form, the relationship is like so class Inspection < ActiveRecord::Base has_many :inspection_components accepts_nested_attributes_for :inspection_components class InspectionComponent < ActiveRecord::Base belongs_to :inspection I have a custom validate method in Inspection which depends on attributes enter...