ruby

How can make my database records automatic

Hi guys, is there any way i can make my records in the database to be automatic. e.g i want a message to be sent to helpdesk if a requested service is not attended within 24 hours, without clicking anything. ...

Help interpreting this bit of Rails code

What is this? "#{h params[:chat_input]}" I am referring to the hash # and the h. ...

Trying to understand use of self.method_name vs. Classname.method_name in Ruby

I'm trying to understand when to use self.method_name vs. when to use Classname.method_name. In the example below, why does "before_create" need to reference "User.hash_password" instead of "self.hash_password" or just "hash_password"? Since we are in the User class already, I thought the before_create method would "know" that "hash_...

Ruby script to read output from alias

Hello, I have setup an alias in /etc/aliases so that each time an email comes in to a specific address, the text of the email is sent to a Ruby script. Like so: example: "|/etc/smrsh/my_script.rb" I need to know how to read the piped data in my Ruby script.. I have written a simple perl script that can read the data.. just can't figu...

Ruby - Map characters to integers in 2d array

Hi everyone, I have a problem I can't for the life of me solve. I'm writing a Ruby app (I've been a PHP developer for 8 years, just starting with Ruby) that sells tickets for a concert hall. Each seat has a row (a...z) and a number (1...x). The database model has row (string) and num (int) for each seat. How can I convert my array of s...

What are some (good) ruby idioms/practices/code snippets?

There has been quite a bit of talk lately on stackoverflow about bad ruby code and practices. I think it is about time we showcase some of the better aspects of Ruby. Instead of showing people all the horrible things Ruby can do lets show people some of the great clarifiers and time-savers of Ruby. One of my personal favorites is multip...

Excel file with multiple tabs

I need to create an excel file with multiple tabs. I need to do this in Ruby on Rails. I have checked out Apache POI but I'm not sure if it provides that functionality. Does anyone know if it does or if there are other alternatives that can do this? Thanks. ...

Is everything an object in python like ruby?

I did google. I may not have searched right. I read on another Stack Overflow question/comment that Python was just like Ruby, as it relates to "everything's and object," and everything in Python was an object, just like Ruby. Is this true? Is everything an object in python like ruby? Thank you. EDIT: How are the two different in ...

How to best copy/clone an entire nested set from a root element down with new tree

I am using "acts_as_nested_set" in my rails app. (extended with awesome nested set plugin). I was trying to logic out the best way to write a function/method to clone an element and its entire nested set so that each element gets a clone but the relationship structure mimicks the original, just with the new elements. With nested sets y...

Should I leave php for Python or Ruby?

First i started with wordpress, than moved to Drupal and realized that any CMS would not fit my needs since i want a really big flexbility in building my aplications (plus i hate to see worthless code, that i will not use but stays there). I give up on already made CMS and started learning php from the begining. But in nearly no time I...

Why does the return keyword cause problems in my 'if block'?

The following code works fine: person = {:a=>:A, :b=>:B, :c=>:C} berson = {:a=>:A1, :b=>:B1, :c=>:C1} kerson = person.merge(berson) do | key, oldv, newv | if key == :a oldv elsif key == :b newv else key end end puts kerson.inspect but if I add the return keyword inside the "if block", I get an error: person = {:a=>:A, :b=>:B,...

Geokit-rails plugin - can't call to_json on returned GeoLoc object, gives circular reference error

I was using an earlier version of geokit plugin on a rails 2.3 app and just updated to this latest version - the one that now uses a gem. In the previous version it was possible to convert the object returned by the .geocode method to json. by just calling the to_json method on it. This however breaks in the new version. I noticed the...

How to do site analytics with ruby on rails

I was wondering what are the options for doing site analytics with a ruby on rails application ? I haven't seen any solutions specifically targeted towards rails - more towards apache type web servers. I don't want to use the google analytics, I'd like to have the logging/analyis all local. After a quick look at wiki's list of web analyt...

what happened to mongrel? any alternatives on windows?

I've jus saw that mongrel's last updat was about one year ago... http://mongrel.rubyforge.org/wiki/WikiStart?action=diff&version=35 has it been disontinued? is there any other lightweight alternative for a windows development box? ...

Which editors are recommended for writing Ruby or Ruby on Rails code?

I'm interested in learning ruby. But the most important thing for me is, if there are any good editors for that. That will help me decide if it's worth to switch from PHP to Ruby. ...

Rails/ActiveRecord: save changes to a model's associated collections

Do I have to save modifications to individual items in a collection for a model, or is there a method I can call to save them when I save the model. #save doesn't seem to do it. For example: irb> rental = #... #=> #<Rental id: 18737, customer_id: 61, dvd_id: 3252, date_rented: "2008-12-16 05:00:00", date_shipped: "2008-12-16 05:00:00"...

Ruby on Rails, ActiveScaffold and relatives in database

I have 2 tables: form, questions. Idea is very easy, every form have many question. Tables were maded form = | id | title | questions = | id | title | input | form_id | and how you can guess the form_id is key of form id. class FormsController < ApplicationController active_scaffold :form end class QuestionsController < Applicatio...

how do you make it so that www.site.com/123 or www.site.com/123/some-headline will both lead users to the same place which is www.site.com/123 ?

how do you make it so that www.site.com/123 or www.site.com/123/some-headline www.site.com/123/anything-at-all will lead users to the same place which is www.site.com/123 ? I think the routing in Ruby on Rails can do it. But other than that, what other methods can do that. can it be done by Apache alone? ...

Ruby-like array arguments implementation in PHP

I program in PHP mostrly and Ruby sometimes I happen to be in need of a way to implements those "hash arguments" into my PHP funcions (Like, say, an HTML select helper) draw_select :name => :id, :onclick => 'alert(this.value)' The problem in PHP is that I would have to define an argument order to implement many possible attributes. I...

Determining if a variable is within range? (Ruby)

I need to write a loop that does something like: if i (1..10) do thing 1 elsif i (11..20) do thing 2 elsif i (21..30) do thing 3 etc... But so far have gone down the wrong paths in terms of syntax. Any help would be much appreciated. ...