ruby

In Ruby, how to implement global behaviour?

Hi all, I want to implement the concept of a Workspace. This is a global concept - all other code will interact with one instance of this Workspace. The Workspace will be responsible for maintaining the current system state (i.e. interacting with the system model, persisting the system state etc) So what's the best design strategy for...

Is Ruby on Rails slow with medium traffic?

Hello ! I made some searches on Google, and I read some posts, articles and benchmarks about Ruby on Rails being slow and I am planning to build one website that will have a good amount of users inserting data and there will be some applications to process this data (maybe in Ruby, you can help me choosing the language). What is the r...

How do I know if a BigDecimal failed to parse?

Hi guys, I'm importing data from a csv, I need to cast some values to BigDecimal, and raise an error if they can't be parsed.. From testing, BigDecimal("invalid number") returns a BigDecimal of 0. This would be ok, but kind of messy, except a valid value is 0... Float("invalid number") acts differently and throws an exception... My ...

Regular expression too big error for cucumber pickle

I am getting below error when i am trying to run my cucumber features. Using the default profile... WARNING: Nokogiri was built against LibXML version 2.7.5, but has dynamically loaded 2.7.6 Strategy is : truncation and ORM is active_record regular expression too big: /^((?:(?:)|(?:(?:a|an|another|the|that) )?(?:(?:(?:(?:first|last|...

How can i make this code, more Ruby-esque?

unless scope.nil? @page ||= Page.find(id, :scope => Page.find(scope) ) else @page ||= Page.find(id) end ...

ruby parametrized regular expression

I have a string like "{some|words|are|here}" or "{another|set|of|words}" So in general the string consists of an opening curly bracket,words delimited by a pipe and a closing curly bracket. What is the most efficient way to get the selected word of that string ? I would like do something like this: @my_string = "{this|is|a|test|case}...

"string_name = string_name[3..-1]" what could the following line of ruby code mean?

Hi, I'm looking at some external code and saw a line of Ruby code that looks like this string_name = string_name[3..-1] what does the [n..-x] do or mean? Thanks. ...

Removing "duplicate objects"

Let's say I have an array of objects from the same class, with two attributes of concern here: name and created_at. How do I find objects with the same name (considered dups) in the array, and then delete the duplicate record in the database. The object with the most-recent created_at date, however, is the one that must be deleted. ...

Rails: unable to set any attribute of child model

I'm having a problem instantiating a ListItem object with specified attributes. For some reason all attributes are set to nil even if I specify values. However, if I specify attributes for a List, they retain their values. Attributes for a List retain their values: >> list = List.new(:id => 20, :name => "Test List") => #<List id: 20, n...

Timeseries transformations in Ruby, Yahoo! Pipes-style

I'm trying to build a system for programmatically filtering timeseries data and wonder if this problem has been solved, or at least hacked at, before. It seems that it's a perfect opportunity to do some Ruby block magic, given the scope and passing abilities; however, I'm still a bit short of fully grokking how to take advantage of block...

How Do I Search Between a Date Range, Using the ActiveRecord Model?

I am new to both Ruby and ActiveRecord. I currently have a need to modify and existing piece of code to add a date range in the select. The current piece goes like this: ReportsThirdparty.find(:all, :conditions => {:site_id=>site_id, :campaign_id=>campaign_id, :size_id=>size_id}) Now, I need to add a range, but I am not sure how to d...

Rails application information

I want to store some information about my rails application, like a version number. I am new to rails and I'm sure there is some sort of convention for doing this. What is the best method of doing this, maybe the environments file? ...

SaaS recurring billing to use with my Ruby app?

I'm trying to add a SaaS recurring billing solution to my app, which is written in Ruby, we use the Sinatra framework and things like Riak. The nice to have would be: A RESTful API Ruby API Returns and get JSON data (since with that will be easy to integrate with Riak) Cheap (we are a startup, so no enterprise solutions) So far I wa...

What database to use with Ruby on Rails, based on actual Hosting services ?

Hello ! I've been looking for hosting services and I still don't know what kind of database is the most commom. It seems to be MySql and PostgreSql. So, I'm not sure about how much traffic and data my website will have (it's just a project), but I would like to be prepared. I've worked in some projects with Oracle (PL/SQL) and I know s...

Ruby parse order

Hi, given this code: class Foo def bar return Bar.new end end class Bar ... end I get this error: NameError: uninitialized constant Bar This obviously works if I put Bar before Foo but that is not a real solution though. Any ideas on how to solve this without considering the order? Many thanks. UPDATE: Of course the...

Ruby complex validation

Have a product that belongs to a category. Want to create a promotion for a short period of time (lets say a week or two), but their can be only one promotion per category during that time. How can I create a custom validation for this? product class belongs_to :categories name:string desc:text reg_price:decimal categor...

Check if file is a valid image

Hi all, I'm using rmagick to manipulate image files. I use the ImageList.new on each file to get started. When I apply this method to an invalid image file I get the below error which interrupts the execution of the script: RMagick.rb:1635:in `read': Improper image header (Magick::ImageMagickError) Therefore I would like to be able to...

Remove duplicate records/objects uniquely identified by multiple attributes

I have a model called HeroStatus with the following attributes: id user_id recordable_type hero_type (can be NULL!) recordable_id created_at There are over 100 hero_statuses, and a user can have many hero_statuses, but can't have the same hero_status more than once. A user's hero_status is uniquely identified by the combination of r...

Rails nested attributes with a join model, where one of the models being joined is a new record

I'm trying to build a grid, in rails, for entering data. It has rows and columns, and rows and columns are joined by cells. In my view, I need for the grid to be able to handle having 'new' rows and columns on the edge, so that if you type in them and then submit, they are automatically generated, and their shared cells are connected to ...

Why am I getting an OpenSSL::SSL::SSLError only on Windows?

I'm downloading files from a HTTPS website. I've narrowed the problem down to this: >> require 'open-uri' >> open('https://www.gmail.com/') # just as an example C:/Ruby/lib/ruby/1.8/net/http.rb:586:in `connect': certificate verify failed (OpenSSL::SSL::SSLError) from C:/Ruby/lib/ruby/1.8/net/http.rb:586:in `connect' from C:/Rub...