ruby

Can't find gems in irb: "NameError: uninitialized constant Gem from (irb)"

When I run a Rails app it finds all of my installed gems correctly. This is the first time I tried to call some gems from inside irb and it couldn't find them. blocke:~$ irb irb(main):001:0> require 'rubygems' => true irb(main):002:0> require 'rails' LoadError: no such file to load -- rails from /usr/local/lib/site_ruby/1.8/rubygems/c...

What gems should I use to have a Ruby app talk to an LDAP server?

My overall goal is to let users of my Rails app authenticate against our organization's ActiveDirectory server over LDAP. (Did I say that right?) I'd like to try the Ruby ActiveLDAP gem. The docs say it depends on either... RubyLDAP or... ruby-net-ldap Does it matter which one I use? Am I heading in the right general direction by ...

Using selenium-client to click a button that is part of a form

Hey, this should be pretty simple, but it's causing me a lot of grief! I have lots of buttons like this: <form class="general" method="post" action="/password"> <div style="margin: 0pt; padding: 0pt; display: inline;"> <input type="hidden" value="Yg4EweyWwXO8RAF9nd3RZKNmQw8Yk+f2vefLQ/IENyg=" name="authenticity_token"/> </div> ...

How to mimic DropBox functionality with Ruby script?

I would like to upload documents to GoogleDocs every time the OS hears that a file was added/dragged/saved in a designated folder, just the way DropBox uploads a file when you save it in the DropBox folder. What would this take in Ruby, what are the parts? How do you listen for when a File is Saved? How do you listen for when a File i...

What is a scripting engine?

I've seen here that what sets a programming language apart from a scripting language is the scripting engine. But I don't understand how it works, so I don't know the difference. For example, I see code in Java calling methods in imported libraries, but it doesn't seem "different enough" from Python or Ruby code - both are scripting lan...

html tidy and rails apps - erb or rthml files. Ruby alternative?

Hi. I just installed HTML Tidy plugin for eclipse. I added the html.erb file type and now it will do its magic on my erb files. However it puts in the title tag and changes a lot of my characters to escape characters. How can I stop this from happening - or is there a ruby alternative which will go through my code, reindent, and stick in...

Linking to external files in ruby?

Sorry if this question is very easy, but I can't find the answer anywhere. How do you refer to an external ruby file in a ruby script if, for example, the file you want is in the same folder as the one you are writing? Thanks in advance. ...

How to upload video on YouTube with Ruby

I am trying to upload a youtube video using the GData gem (I have seen the youtube_g gem but would like to make it work with pure GData if possible), but I keep getting this error: GData::Client::BadRequestError in 'MyProject::Google::YouTube should upload the actual video to youtube (once it does, mock this test out)' request error 400...

Sort collection of object in rails ?

I know I can use something like User.sort {|a, b| a.attribute <=> b.attribute} or User.find and order, but is it a way like comparable interface in Java, so every time I called sort on User object it will do sort on the predefined attributes. Thanks, ...

Running C processes in Rails

Hi there I make a call just like this: value = ./simulated_annealing Which is a C Object file, but Rails tells me it cannot find that file. I put it in the same dir that the rest of the models files (since it's called by one of those models), but I guess it should be in any other place. I've tried that outside Ruby and it works great...

Best way to model these Rails relationships

Hi, I have the following scenario that I want to model the best way for a Rails application. I have a contact model that belongs to a company. A contact can create an enquiry so contact can have many enquiries. The enquiry can have many messages that can be from and to many contacts. Messages can belong to an enquiry, a company or a...

Instance variable: self vs @

I saw a code class Person def initialize(age) @age = age end def age @age end def age_difference_with(other_person) (self.age - other_person.age).abs end protected :age end What I want to know is how difference between using @age and self.age in age_difference_with method. ...

Initialize in Ruby

I used to have this public constructor_name() { this(param) } public constructor_name(int param) { this.param = param } in Java and what about ruby do we have this kind of self reference constructor ? ...

Adding to RSpec's search path

I'm using a mocking framework add-on to RSpec called NotAMock (http://github.com/notahat/not%5Fa%5Fmock). I am modeling a business layer in Ruby, so my project consists of mostly plain-old Ruby objects (PORO's). I've put my specs in a 'specs' directory off of the project directory, and put NotAMock within the specs directory. When I r...

# TODO in rails

I had read through a rails book and once found we can add # TODO: and some # stuff in codes, so we can you some rake cmd to look back. My problems is I can't find where are those "# stuff" and "rake cmd" I google and search around, but can't find and don't know what keywords to search. Thanks, ...

In ruby, how to decrypt a string which is encrypted by "crypted" method

In ruby, I encrypt a string using "crypt" method, for example: str = "123" strencrypt = str.crypt("aa") I want to decrypt from strencrypt and obtain the original string. How can I achieve that? I have tried to use crypt method again: str_ori = strencrypt.crypt("aa") But it can not return the "123". Anyone can help me? ...

One Controller Action or Two for Ruby on Rails pages

I currently have one model, one controller with one action to list all the items in the model. What I need to do is display different data from the model in two separate views. Is there a way I can use one controller action to display different views based on params, or should I create another action? The reason why I hesitate to crea...

Ruby: Creating nested FOR loops (varying depth) for varying number of Arrays.

I have varying number of arrays within one giant array. (is this the right approach?) parentArray = [[array],[array2],....] how can i create a series of nested loops for each consecutive array ? So creating array loops within the previous one. parentArray.each do |eacharray| array.each do |eacharray1| array2.each do |eacha...

recursive nested loops.

Example Scenario: Note, this can be as deep or as shallow depending on the website. Spider scans the first page for links. it stores it as array1. spider enters the first link, it's now on second page. it sees links, and stores it as array2. spider enters the first link on the second page, its now on third page. it sees links upon, an...

How do I find gems that depend on a given gem?

Is it possible to search for all gems that rely on a certain rubygem? For example, I'd like to ask for all gems in gemcutter that rely on the test-unit gem. Background: I'm looking to see how other gems handle the issue mentioned here. ...