Hi all,
Let's go to the code directly :)
#!/usr/bin/ruby
require 'tk'
class Epg
def initialize
@var = "bad"
@cvs = nil
@items_demo = TkRoot.new() {title "EPG"}
TkFrame.new(@items_demo) {|cf|
@var = "good"
@cvs = TkCanvas.new(cf) {|c|}
puts "@cvs 1 is #{@cvs}"
puts "@var 1 is #{@var}"
}.pack('side'=>'top', 'fi...
I want to do something different with the last loop iteration when performing 'foreach' on an object. I'm using Ruby but the same goes for C#, Java etc.
list = ['A','B','C']
list.each{|i|
puts "Looping: "+i # if not last loop iteration
puts "Last one: "+i # if last loop iteration
}
The output desired is equivalent to:
...
We have a class Car defined like this in a car.rb file
class Car
end
then, we have another class Car defined in electric/car.rb
require "../car.rb"
module Electric
class Car < Car
end
end
Unfortunately, it seems that we can't inherit from the first class. Why is that?
...
In my Rails 2.3.2 app
I have 2 models:
class Post
has_many :approved_comments, :class_name => 'Comment', :conditions => ['approved => ?', true]
end
class Comment
belongs_to :post
end
For some reason when I try to eager load my comments, I get an error
post = Post.find(:first, :conditions => ["permalink=?", permalink], :includ...
I'm really enjoying Rails (even though I'm generally RESTless), and I enjoy Ruby being very OO. Still, the tendency to make huge ActiveRecord subclasses and huge controllers is quite natural (even if you do use a controller per resource). If you were to create deeper object worlds, where would you put the classes (and modules, I suppose)...
Here is a class that I used to have
class Something
# Defines the validates class methods, which is called upon instantiation
include Module
validates :name
validates :date
end
I now have several objects that are using the same functionalities, and worse, several object that are defining similar things, like this:
c...
Hi,
I'm writing a client that consumes a non-REST API (i.e. GET site.com/gettreasurehunts), which requires that I specify all parameters (even the resource ID) in the request's HTTP body as a custom XML document.
I'd like to use Rails and ActiveResource, but I'd be forced to rewrite almost all of ActiveResource's methods.
Is there anot...
Hey,
I'm using Eclipse with RDT to do some Ruby programming. I'm trying to include a file in another, but require fails. Both files are in the same directory.
The folder hierarchy is set up like this:
Project > src > folder > a.rb b.rb
If I try to require b.rb in a.rb I would use this:
require 'b.rb'
But I get the following error ...
I have this rails app that's running on our local intranet, with a thousand regular users. I am looking to integrate it with our email server(MS Exchange). Basically -
1) For each user, the app should fetch any new messages in their inbox from the mail-server, parse it, and file it in the database.
I could implement it with ruby/net-im...
This is a continuation of this question:
Original Question (SO)
The answer to this question involved the following set of models:
class User < ActiveRecord::Base
has_many :friendships
has_many :friends, :through => :friendships #...
end
class Friendship < ActiveRecord::Base
belongs_to :user
belongs_to :friend, :class_name => '...
I'm trying to get migrations set up in Ramaze. I'm coming from doing mostly Rails stuff, but I wanted to give something else a shot. Anyway, I've got a directory in my project called "migrations" with a start.rb file and then my migrations. Here's start.rb:
require File.expand_path('../app.rb', File.dirname(__FILE__))
require 'sequel/ex...
I have a ruby application that executes ant as a subprocess using backtick. This works without any problems. When I do puts ant, ruby waits for the subprocess, ant, to finish completely and then prints the output to stdout. How do I get ruby to print the output from the subprocess continuously?
...
Hey,
I asked a little earlier about a clever way to execute a method on a given condition see here
The solutions (and response time!) was great, though upon implementation having a hash of lambdas gets ugly quite quickly. So I started experimenting.
The following code works:
def a()
puts "hello world"
end
some_hash = { 0 => a() }
s...
Hey,
I'm implementing a few things in Ruby and I was wondering how much error checking is appropriate (or, more precisely, how much error checking should be done by convention)?
For example, I'm implementing a method which swaps two elements in an array. The method is very simple:
def swap(a,b)
@array[a], @array[b] = @array[b], @arr...
I am trying to make Authlogic and Facebook Connect (using Facebook) play nice so that you can create an account either the normal registration way or with Facebook connect. I have been able to get the connect to work one way but logging out only loggs out on facebook and not on my site, I have to delete the cookies to make it working. An...
We are using Ruby on Rails code to import the data from an Excel sheet, we use an alert where it asks whether we upload the data and append to existing data (MySQL database) and display it in a grid designed in Flex 3, or replace the old data with new data. But we are getting this error:
Error in Importing excel files Open
OLE error cod...
Basically I want to implement a simple Rails extension to define the seriousness of methods in my controller so that I can restrict usage of them appropriately. For example I'd define the default restful actions as so in an abstract superclass:
view_methods :index, :show
edit_methods :new, :create, :edit, :update
destroy_methods :destro...
I am writing a custom wrapper for open_flash_chart plugin. It's placed in /lib and load it as a module in ApplicationController.
However, I have some Class hierarchy or smth problem.
From any controller I can access open_flash_chart functions as OpenFlashChart, Line etc
However, in a class in a /lib module, it doesnt work!
Any ideas?...
As part of my Ruby on Rails application, I need to perform several (a few dozen) web requests to a foreign web server -- all on the same domain. I am aware of the two requests per domain throttle on Windows and know how to adjust that, but this application is running on CentOS and I was not expecting to run into this same issue, but I se...
Hello,
I'm starting in the Rails world and i want to know how to put an login system like that here in Stack Overflow uses. Thanks, and remember that i'm starting, and if you can post a link to a very good tutorial, is very nice.
...