ruby

Generate information based on content in RoR, any ideas on that?

I have many products, each product belong to one category. How can I generate each category in hyper text, and when I click on the category hyper text, I can get all the products which is belongs to this category. And ideas on that? ...

Rails: Link to partials?

Hello! At the moment I try to do following: I created several partials (i.e. _show_signature.html.erb) for my user. Now I want to show them on clicking a link. In my user controller, I created a new action: def show_signature @is_on_show_signature = true end def show_information @is_on_show_information = true end ...

Ruby: Deleting last iterated item?

What I'm doing is this: have one file as input, another as output. I chose a random line in the input, put it in the output, and then delete it. Now, I've iterated over the file and am on the line I want. I've copied it to the output file. Is there a way to delete it? I'm doing something like this: for i in 0..number_of_lines_to_remov...

Change value of request.remote_ip in Ruby on Rails

For test purposes I want to change the return value of request.remote_ip. While being on my development machine it returns always 127.0.0.1 as it should but I would like to give myself different fake IPs to test the correct behavior of my app without deploying it to an live server first! Thank you. ...

How are variables bound to the body of a define_method?

While trying to brush up my Ruby skills I keep running across this case which I can't figure out an explanation for by just reading the API docs. An explanation would be greatly appreciated. Here's the example code: for name in [ :new, :create, :destroy ] define_method("test_#{name}") do puts name end end What I want/expect to...

How do I create a hash in Ruby that compares strings, ignoring case?

In Ruby, I want to store some stuff in a Hash, but I don't want it to be case-sensitive. So for example: h = Hash.new h["HELLO"] = 7 puts h["hello"] This should output 7, even though the case is different. Can I just override the equality method of the hash or something similar? Thanks. ...

How does Integer === 3 work?

So as I understand it, the === operator tests to see if the RHS object is a member of the LHS object. That makes sense. But how does this work in Ruby? I'm looking at the Ruby docs and I only see === defined in Object, I don't see it in Integer itself. Is it just not documented? ...

Why should Ruby not be used to create a spider

In Episode 78 of the Joel & Jeff podcast one of the Doctype / Litmus guys states that you would never want to build a spider in ruby. Would anyone like to guess at his reasoning for this? ...

extjs status bar and validation checks

I'm using the sample extjs status bar, the one with the word count demo. I set the name and id of the text area within my JS file to match the other form items on the page (in this case something like, user_description and user[description]) However when it throws back an error with validation of the description being over my limit, it "...

What are the uppercase and lowercase rules of ruby method name?

I am a ruby beginner. From the book, I know that ruby method name should start with a lowercase letter ( or underscore). But I found different scenarios: if a method is defined outside a class, it can only begin with lowercase letter, Ruby will complain error if you try to define a method which begin with uppercase letter, for example...

Get info about error when using Eventmachine Http Request

When using Eventmachine to asynchronously execute an HTTP request, either by using em-http-request or some other means, is it possible to get information about the error in the errback callback? Like connection error vs. timeout vs. invalid response? ...

Any way to add gems to specific environments using Rails Template?

I'm building my Rails template right now. Rails template is a way to generate a skeleton app. http://railscasts.com/episodes/148-app-templates-in-rails-2-3 http://m.onkey.org/2008/12/4/rails-templates I would like to add some gems to test.rb and development.rb, but not environment.rb. But I don't find a way to do so other than manua...

Have radio button's label make selection too?

According to (somewhat official) this guide, I can make a radio button's label make the selection for that radio button too. They say, Always use labels for each checkbox and radio button. They associate text with a specific option and provide a larger clickable region. Unfortunately, I have not been able to get this functionality...

Dynamic change of "each" loops in Ruby

Dear Colleagues I am a newie in Ruby and I am facing a problem regarding "each"-like loops. Suppose a code like the following startIndex = 1 endIndex = 200 (startIndex..endIndex).each do |value| p value if value>150 then endIndex=100 end When I run the code it will run until 200, not until 150. Is there any way to change the l...

Syntax for a for loop in ruby

How do I do this type of for loop in Ruby? for(int i=0; i<array.length; i++) { } ...

Can I use stored procedures with ruby on rails ?

Can I use stored procedures with ruby on rails ? I am using mysql as database and ruby on rails. please provide me any of the example for this. ...

I am creating a Twitter clone in Ruby On Rails, how do I code it so that the '@...''s in the 'tweets' turn into links?

I am somewhat of a Rails newbie so bear with me, I have most of the application figured out except for this one part. ...

Validate FK now or recover from later?

What's the more accepted Rails approach? Validate that a foreign key exists on creation/update or "Damage control" when we want to use the non-existent foreign key? Initial validation requires more resources on row creation/updating, and may even be redundant when I'm creating rows systematically in my code (i.e. not user generated)....

What's the Perl equivalent of Ruby "foo".hash ?

The hash method on a Ruby String returns a number based on the string's length and content: >> "foo".hash => 876516207 What's the equivalent in Perl? ...

Simple question about an if block in Ruby on Rails

Hi, I am trying to tell ruby to not run a block of html and ruby if no active record exists in the database. Below is the code I was trying to run conditions on. <% if @statemant.comments.exists?() do %> <div id="comments"> <h2>Comments</h2> <%= render :partial => @statemant.comments %> </div> <% end %> ...