ruby

How do I do a has_many through association on a has_many through association in rails?

Warning: I may have the wrong 'problem statement' but here it goes: A Campaign has many Contacts. A Campaign has many Emails. Therefore, a Contact has many Emails through a Campaign. And an Email can have many Contacts through a Campaign. Each Contact-Email pair has its own unique Status (status1, status2, etc). Each Status (for a ...

What's discouraging you from writing ruby 1.9-specific code?

So far, I've been merely using YARV (ruby 1.9) as merely a faster implementation of ruby than ruby 1.8, and ensured that all of my code is backwards-compatible with ruby 1.8.6. What circumstances, if any, are stopping you from writing 1.9-specific code? One reason per answer. ...

How to call cgi script from ruby

Hello, I've a remote cgi script hosted on Apache using SSL. It takes in two input variables a and b. I want to call call the cgi script with right input variables using ruby. Any clues would be appreciated. ...

Apart from SCITE can anyone recommend a good tool for programming Ruby

I have used SCITE for a few weeks now, wondered if there was an better alternative. ...

How to simplify ruby block with one argument?

Somewhere i saw a way to simplify ruby blocks with one argument, it basically omitted vertical bars and argument declaration, because it was somehow inlined. I cannot find it anymore or remember any names t osearch for. Can you help? ...

Silencing Deprecation warnings in Rails 3

Can anyone tell me how to silence deprecation warinings in Rails 3? I have a few situations where it is throwing false positives. Namely using - for loops in haml and f.error_messages from the dynamic_form plugin. Thanks ...

Beginner to RUBY - Array Question

a = [ 1, 3, 5, 7, 9 ] → [1, 3, 5, 7, 9] a[2, 2] = ’cat’ → [1, 3, "cat", 9] a[2, 0] = ’dog’ → [1, 3, "dog", "cat", 9] a[1, 1] = [ 9, 8, 7 ] → [1, 9, 8, 7, "dog", "cat", 9] a[0..3] = [] → ["dog", "cat", 9] a[5..6] = 99, 98 → ["dog", "cat", 9, nil, nil, 99, 98] I can understand how the last...

Processing multiple arrays simultaneously in ruby

I have an array : a=[[1,2],[3]] and b=[[2,3],[5]] i need to add corresponding elements in each array simultaneously in order to obtain the result; result=[[3,5],[8]]. Thanks and Cheers! ...

Create a set column with database migration in rails

Hello. I need to add a new column to my users table in the database. I want the type of the column to be set. The column represents the users gender. There should be two options to the set. One form Male "m" and the other for Female "f". But i havent found any doccumentation for adding a column with the set type. How can i do this? ...

Call method on included class in Ruby

How do you call the method of an included class in Ruby? See the example below. This works, but it is not what I want: require 'httparty' module MyModule class MyClass include HTTParty base_uri 'http://localhost' def initialize(path) # other code end end end This is what I want, but doesn't work, s...

Is there any Ruby web app/gem which offsers a web shell?

Is there any Ruby web app/ gem which allows you to administrate a computer ( I'm mostly interested in running shell commands ) through a web interface? ...

How to add a has_many association on all models

Right now I have an initializer that does this: ActiveRecord::Base.send :has_many, :notes, :as => :notable ActiveRecord::Base.send :accepts_nested_attributes_for, :notes It builds the association just fine, except when I load a view that uses it, the second load gives me: can't dup NilClass from: /usr/lib/ruby/gems/1.8/gems/activereco...

CentOS 5.4 and Rubyworks -- its getting old

The Rubyworks repository is a great solution to getting a newer version of the ruby stack installed on CentOS, however, its beginning to show its age with ruby 1.8.6 (2007-09-24 patchlevel 111)... Are there other repos or up-to-date packages already built for CentOS out there or must I resort to compiling from source? ...

Dropbox like service with git -- no with rsync and inotify

Do you have any advice as how to setup a Dropbox like service using git? Do you think git is the right tool for this? I was thinking about using a git + rush solution what do you think about it? ...

How to make the 'week' starts with a specific day not Monday?

In an application am building, i'm trying to make the week starts with Saturday. In ruby on rails, by default, the week begins on Monday. So If you have any trick or a patch to make it work for me! Thanks in advance! ...

[Rails] Calling a method from a view using link_to_function

Hello! I'm trying to have an image that when clicked associates the selected guideline to a project. I'm using link_to_function which somewhat behaves but I can not get the method I am calling in the link_to_function to redirect to another page. Is there a better way to do this? Below is a bit of my code. I can paste in additional parts ...

Sinatra: How do I provide access to a login form while preventing access to the rest of my Sinatra app?

I recently created a Sinatra app with a login form (no basic auth). To prevent access to the app unless the user logged in I put a before block in place before do unless request.path_info == '/login' authenticated? end end I quickly realized that this prevented me from accessing resources in the public directory like my style...

Hash default value not being used

Today I tried the following snippets of code and I don't understand why I get different results between them. As far as I can understand they are the same. One uses the default value off Hash and the other snippet creates an empty array for the key before it'll be accessed. Anyone who understands what's going on? :) # Hash default if ...

Wrap text around an image in rails and prawn

I have a document with dynamic image and dynamic text and would like the text around the image. The image is right aligned on the landscape page. Here is what I have so far: pdf.bounding_box([0,pdf.bounds.top - 50], :width => pdf.bounds.width, :height => pdf.bounds.height-50) do pdf.text @article.title, :size => 30, :style => :bold ...

Ruby on Rails: How do you add add zeros in front of a number if it's under 10?

I'm looking to convert single digit numbers to two-digit numbers like so: 9 ==> 09 5 ==> 05 12 == 12 4 ==> 04 I figure I could put a bunch of if-else statements (if number is under 10, then do a gsub) but figure that's horrible coding. I know Rails has number_with_precision but I see that it only applies to decimal numbers. Any ideas ...