ruby

Ruby on Rails: At what point do you write raw javascript instead of using rjs templates?

As a new comer to writing front-end views with Rails, I'm a bit confused as to when I should be using rjs templates versus when I should be writing my own JavaScript to handle events/DHTML. Is there some rules you avid Rails developers follow for when something is too complex or not possible with RJS and you just write the JavaScript you...

Retreiving user details using openid

I am using the open_id_authentication plugin for login purpose. I am able to integrate the plugin correctly and it works well. I would like to retrieve additional values like the nickname and email of the user, which I am not able to retrieve. I am using the following code but the registration fields are empty . Am I doing something corr...

Question on Rails Helper classes & modules

So this is a newbie rails design question. Lets say I want some of my common functionality to be sitting in a set of helper classes (either as class methods or instance methods). And I want to use these helper objects inside controller (not view) or even may be a model. can I do that? how? Does it have to be a module or class or can be ...

DataMapper association: How do I specify table name that contains the associated rows?

I am working with a database that is already in place and used by other applications. The people who designed the database did not use pluralized table names, so DataMapper chooses the wrong table name when following associations. For instance: class Foo has n :components # => the table name here should be COMPONENT, but datamapper ...

How can I use Array#delete while iterating over the array?

I have an array that I want to iterate over and delete some of the elements. This doesn't work: a = [1, 2, 3, 4, 5] a.each do |x| next if x < 3 a.delete x # do something with x end a #=> [1, 2, 4] I want a to be [1, 2]. How can I get around this? ...

'Splitting' ActiveRecord collection

Let's say I have two models Post and Category: class Post < ActiveRecord::Base belongs_to :category end class Category < ActiveRecord::Base has_many :posts end Is there a method that will allow me to do something like posts = Post.find(:all) p = Array.new p[1] = posts.with_category_id(1) p[2] = posts.with_category_id(2) p[3] =...

ruby on rails multiple object in find condition

Hi How can I add multiple objects in a find condition? I created a table for comment but I want to display comments posted by a user and His or her friends. I got the find method to return a list of comments by a users friends but I cannot get the Find method to include the user as well. For example User = profile.find(1) Comment.fi...

Looking for an alternative to eval

Hi, I'm new to ruby however it isn't really that drastic of a change coming from perl, anyways 've written a simple script to convert my gobs of perl Data::Dumper output into yaml configs, my problem is I'm using eval to accomplish this and seeing as I may like others to use this script one day I would like to eliminate eval for somethin...

Recommended TextMate Bundles for Ruby on Rails Development

Can you guys please recommend few textmate bundles that would be helpful while developing ruby on rails applications ...

simile timeline search

I want to filter the content in a simile Timeline display on some field other than description.Is it possible? ...

Website Script that will click on button every x seconds...

Is there an easy way of automating clicking on a certain button on a website? I'm trying to help someone in my company out, the guy basically stares a booking page the entire day, having to click on a single button to refresh the page. If new booking slots becomes available, then it will only be shown on the page on the page refreshes, ...

Changing type of ActiveRecord Class in Rails with Single Table Inheritance

I have two types of classes: BaseUser < ActiveRecord::Base and User < BaseUser which acts_as_authentic using Authlogic's authentication system. This inheritance is implemented using Single Table Inheritance If a new user registers, I register him as a User. However, if I already have a BaseUser with the same email, I'd like to ...

How do I get the version from a gemspec file?

Is there a clean way to extract the version string from a .gemspec file? (The gem is not yet installed) e.g. somethingcool.gemspec is Gem::Specification.new do |s| s.name = "somethingcool" s.version = "1.2.3" ... etc ... end I want to extract "1.2.3". I could grep it out but there must be a better way. ...

Editing a YAML file inside a Rails App

I'm trying to use a yaml config file as a very simple flat file db for a small rails app. The app has a single user, so I just need a way to store a username and password. The only thing is that I'd like to be able to edit the username and password while still inside the app and not require an app restart (so I can't load the YAML file...

Simile Timeline filtering content

I am using simile Timeline to display events in event table from my database, where i am loading data using xml, <data> <event eventType="Happy" title="My Birthday" end="2010-08-15" start="2010-08-15" isDuration="false">Party time </event> </data> This would display title,description,start date and end date on simile, but I also want...

Is there something similar to JLS for Ruby

Is there a definitive specification for Ruby, akin to the Java Language Specification for Java. Googling ruby language specification provides http://ruby-std.netlab.jp/ as a result, but the site is down and i am not sure whether it is current ...

how to write a program to validate another program/script?

How to write a program to test another program/script? I need to test a ruby script that is an echo server; how should I write a program to validate the correct working of the echo server script ? ...

Rails: cattr_accessor and class variables

Running this code: module A def self.included(klass) klass.send(:cattr_accessor, :my_name) end def set_my_name_var @@my_name = 'A' # does NOT work as expected end def set_my_name_attr self.class.my_name = 'A' # works as expected end end class B include A cattr_accessor :my_other_name def set_my_other_...

URL rewriting in ROR

I am Amit. i am new to Rails. Please forgive me if ask any stupid questions. I have gone through this article. I am also suffering with the same problem. my website URL like this: locahost:3000/users/edit/30 I don't want to show the controller:users and action: edit. I want to Re-Write (rewrite) the URL or i want to maintain the URL...

how to put assertions in ruby code

I want to use the assertions and put valuidations in my ruby code (e.g: checking if a zip file is created, label is present, message in the text area, etc). I have put a few assert statements like assert @selenium.is_text_present(textMessage), but they don't work. Please let me know if any ruby gem for assertions is to be installed. ...