Parsing a String in Ruby for multiple values?
How can I parse the following string: Phone + 300 mins & unlimited texts - 24 month plan $25 to obtain the bracketed values, i.e. Phone + [300] mins & [unlimited] texts - [24] month plan $[25] ...
How can I parse the following string: Phone + 300 mins & unlimited texts - 24 month plan $25 to obtain the bracketed values, i.e. Phone + [300] mins & [unlimited] texts - [24] month plan $[25] ...
Hello I'm trying to create a BBcode [code] tag for my rails forum, and I have a problem with the expression: param_string.gsub!( /\[code\](.*?)\[\/code\]/im, '<pre>\1</pre>' ) How do I get what the regex match returns (the text inbetween the [code][/code] tags), and escape all the html and some other characters in it? I've tried thi...
I have a "category" table that contains different kind of "product", so I create this in the category.rb: class Category < ActiveRecord::Base has_many :products end And this in product.rb: class Product < ActiveRecord::Base belongs_to :categories end I would like to know how can I get the :categories From the product in the pro...
I have vanilla Mac OS X Leopard which comes with 1.8.6. I am new to RoR so will be following tutorials on the net. Am I likely to find problems following them when using later versions of Ruby? I am currently looking at this one which mentions 1.8.6 and 1.8.7 - http://www.railstutorial.org/book ...
Hello, I have a posts model which has_one reposts and has_one sponsored. User can purchase reposts and sponsored posts while creating a post. I want that the minimum purchase(sum of reposts and sponsored purchases) be atleast 1$. so i want to validate this in the post model but i can't figure out on how to write such ...
hey guys, i'm trying to set up a server for integration tests (specs actually) via ruby and can't figure out how to control the process. so, what i'm trying to do is: run a rake task for my gem that executes the integration specs the task needs to first start a server (i use webrick) and then run the specs after executing the specs i...
I'm using MongoDB as a backend for a Rails app I'm building. Mongo, by default, generates 24-character hexadecimal ids for its records to make sharding easier, so my URLs wind up looking like: example.com/companies/4b3fc1400de0690bf2000001/employees/4b3ea6e30de0691552000001 Which is not very pretty. I'd like to stick to the Rails url ...
For reference, this question was boggled, so thanks to everyone who helped unboggle it. I'm trying to locate potential collisions of events in a booking program where events have varying lengths. (a ≤ x && e ≥ y) || (a ≥ x && e ≤ y) || (a ≤ x && e ≤ y) || (a ≥ x && e ≥ y) I'm using DataMapper to accomplish this, but the query I had be...
I have seen the run_once method in some code like run_once do [:hello, :core, :gems, :plugins, :lib, :initializers, :routes, :app, :helpers].each do |f| require File.join_from_here('mack', 'boot', "#{f}.rb") end end I found it in Kernel, but not sure what it does... something to do with running once I guess... ...
I'm having a weird problem. I do a deploy and then the dir that just got uploaded is then deleted by the cleanup task. I haven't deployed to this site in well over a month but I didn't change the deploy recipe. Any ideas? Here's the output. http://gist.github.com/267850 ...
Hi, I have an object called Review which :belongs_to two objects: Users and Vendors. In other words, there is always a vendor writing a review for a specific vendor. When I create a review, I tried to use the .build method to presumably add the foreign_key at the time the new record is created for review.vendor_id and review.user_id. ...
Ok, so everyone knows that capitalised identifiers are seen to be ‘constant’ in Ruby. However, it is possible to assign a new value to constants, so the following works class A def self.hi; "hi"; end end class B def self.hi; "ho"; end end A.hi # => "hi" B.hi # => "ho" A = B # warning: already initialized constant A # => B A.hi # =...
following up with this topic: http://stackoverflow.com/questions/1992094/one-to-many-relationship-in-ror I am creating a category that may have many products. So, I use the Formtastic as user Chandra Patni suggested. But I find there is a problem when I added attr_accessible to the product.rb. class Product < ActiveRecord::Base valid...
Connecting to postgres with rails was no big deal. rails -d postgresql app_name, setup the database.yml and voila. I cannot, however, use postgres with just a little test script I've tried installing the gems postgres, dbi & dbd-pg, pg, and ruby-pg, but with pg/ruby-pg and postgres it fails at the require for require 'postgres' or req...
Hi, I am trying to understand this code snippet: while row = input.gets row.strip! next if row.empty? valuesplit = row.split("---") a, b = valuesplit[1..2] unless a == b $hash1[a] ||= {} <--------------What is this line doing? How is the whole loop $hash1[a][b] = true being traversed? if $hash1[b]...
Basically the title says it all What I mean is differentiation and integration stuff that a CAS would do? (like a Typical handheld CAS if not better) Is it possible? What Gem need to be installed? Anyone had any experience? ...
I have created a Model class where I define methods based on a method (attribute) called in User (which inherits from Model). The problem is that I cannot override the method defined by define_method, and call super to pass to the defined method. I guess this is because the defined method is added to User itself, and not to the Model, so...
I have a background from languages which use {} to say that these are "block of statements" but i am learning ruby and really confused how it being done there. So lets say in C i have if ( condition ) { statement1; statement2; } else if (condition) { statement1; statement2; // nested if if (condition) { ...
I've been struggling on this rails app for the past week and a half – any help would be appreciated. Im running from a windows machine [vista]..using: latest rails to date [jan 2. 2010], capistrano 2.5.10, subversive plugin, TortoiseSVN I've so far:- created the remote repository, created ssh keys, edited the TortoiseSVN config file. N...
I'm looking for a way to convert text like this: " <!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n <html xml:lang=\"en\" lang=\"en\" xmlns=\"http://www.w3.org/1999/xhtml\">\n \t<head>\n \t\t<title>My Page Title</title>\n \t\t<META HTTP-EQUIV=\"Content-T...