I have the following scenario
class XYZ < ActiveRecord::Base
has_many :abcs
end
class ABC < ActiveRecord::Base
belongs_to :xyz
end
class A < ABC
end
class B < ABC
end
class C < ABC
end
The model ABC doesn't have any controller, or view. Data related to ABC will be inserted from the XYZ views and controllers. The user sets a type v...
Is there a way to put the terminal on the web browser instead, so I just fire up localhost:80 and then I'll have a terminal on it that I can use and whatever I execute it will execute on my local web server?
And the outputs I want to be displayed on the web browser too, just like a normal Terminal.
I'm using Ruby on Mac OS X/Ubuntu.
...
I am having two domains running each a separate web application that should be served by one server i.e. one ip address. Depending on the request the proper application should be selected by some rack middleware. Is there already one out or do I have to write my own? (Writing my own wouldn't be a problem but if I could use an existing on...
In most other languages, the catch and throw statements do what the begin, rescue, and raise statements do in Ruby. I know the you can do this with these two statements ...
catch :done do
puts "I'm done."
end
if some_condition
throw :done
end
But what is this useful for? Can somebody please give me an example of what catch and th...
Possible Duplicate:
How to get a random number in Ruby?
I am just curios but does Ruby have a class for specifically generating random numbers like Java's java.util.Random class, or is the rand method all Ruby has?
...
I have a signup form, and I wanted to make it so that they have the option of recommending this signup to all their friends in facebook.
Is there a rails API/gem for doing this?
Is there an appropriate name for this?
Thanks!
...
I would like to parse a CSV file so that each row is treated like an object with the header-row being the names of the attributes in the object. I could write this, but I'm sure its already out there.
Here is my csv
"foo","bar","baz"
1,2,3
"blah",7,"blam"
4,5,6
So the code would look something like this.
CSV.open('my_file.csv','r') ...
Possible Duplicate:
Why doesn't Ruby support i++ or i for fixnum?
Why is there no increment operator in Ruby?
e.g
i++
++i
Is the ++ operator used for something else? Is there a REAL reason for this?
...
In want to automate a task in windows word 2007 with ruby.
I have in the document several chapters with tables.
This tables include some GUI descriptions (Label 1, Label 2, ...).
Chapter 1
Table 1
Label 1 ipsum
Label 2 lorem
...
Chapter 2
Table 2
Label 3 ipsum
Label 4 lorem
...
...
The problem ...
Here is my case:
I want to use a web browser to connect to a Rails application that runs this example code on the server side:
Dir.chdir path_typed_in_by_user
system "ls -la"
I want the output of "ls -la" to be displayed on the web browser.
Is this possible somehow?
...
In Ruby, I have code similar to the following
foo { |x, y| puts y }
Because the compiler/interpreter keeps warning me about the unused var X, I replaced x with a '*' and the compiler stopped complaining. (I don't know why I decided * was the best choice... It just happened...)
foo { |*, y| puts y }
What does this do exactly? And a...
I am having a hard time understanding what the shift and unshift methods of the Array class do in Ruby. Can somebody help me understand what they do?
...
I have a script I want to execute with open4.
Here is the file:
script
#!/usr/bin/env ruby
print "Enter your username: "
username = gets
puts "Here is your username: #{username}"
print "Enter your password: "
password = gets
puts "Here is your password: #{password}"
Then I fire up IRB and type:
ruby-1.9.2-p0 > pid, stdin, stdout, s...
i'm a .net guy doing some work/learning RoR. i have a handful of environment-specific settings i'd like to externalize (s3 access info). what is the way to do this? I realize the place for it is in config/environment/[environment], but i'm asking beyond that. Should it be a global constant? should i use an initializer? how do i cleanly m...
I have an email form. But I'm making a test email form where a user can add a unique email, and have the email test send it to that particular email.
To make it easy, I decided to make the test email perform via ajax, and stick the whole thing inside of the other email form.
I can't figure out how to send the variables from my HAML to...
Forgive me, guys; I'm still a complete RoR newbie.
I'm trying to use the will_paginate gem to add pagination to search results in my Rails app. Thus far it's been working great. However, I've hit a roadblock.
I have a "products" table with thousands of records that I want to be completely browsable. This is easy in the most basic scena...
I am using the following logic to update a list item based on a criteria.
def update_orders_list(order)
@orders.delete_if{|o| o.id == order.id}
@orders << order
end
Ideally, I would have preferred these approaches:
array.find_and_replace(obj) { |o| conditon }
OR
idx = array.find_index_of { |o| condition }
array[idx] = obj
Is...
I am learning ruby and about modules and mixins..
I tried the following code. The name of the ruby file test.rb.
module Mod1
def Mod1.sayHello()
puts "Hello Mod1"
end
end
module Mod2
def Mod2.sayHello()
puts "Hello Mod2"
end
end
class TestMod
require 'file'
Mod1.sayHello
end
t = TestMod.new
I am suprised to t...
Here's an unexpected find. Something of a very basic Ruby issue that I haven't happened to run into before:
a = "a"
if a
test = "yes" if a == "a" else "no"
else
test = "no"
end
Running this yields the error:
syntax error, unexpected kELSE, expecting kEND
Looks like the nested oneliner spills out into the enclosing if statement...
I am using the HTTPWatch Ruby script to automate Internet Explorer and crawl a website looking for broken links. See here for information on the ruby site spider script. After a while the HTTPWatch plugin fails with the following error:
Get Cache Object failed # 1. len = 2048 url = http://domainname/dckh1h0mntja0m8xa1qugzm3n_59c9/dbs....