I am working on a simple relationship with DataMapper, a ruby webapp to track games. A game belongs_to 4 players, and each player can have many games.
When I call player.games.size, I seem to be getting back a result of 0, for players that I know have games associated with them. I am currently able to pull the player associations off of ...
I am trying to iterate a multidimension array created with the following line
To iterate i'm using the following code
visiblematrix= Array.new (10) {Array.new(10){0}}
But this doesn't allow me to know the current x,y position while iterating. how can i find it out without resorting to temporary variables
visiblematrix.each do |x|
...
Hi,
I have some URLs, like http://www.example.com/something?param1=value1&param2=value2&param3=value3, and I would like to extract the parameters from these URLs and get them in a Hash. Obviously, I could use regular expressions, but I was just wondering if there was easier ways to do that with Ruby or Rails. I haven't found an...
Imagine the following use case:
You have a basecamp style application hosting files with S3. Accounts all have their own files, but stored on S3.
How, therefore, would a developer go about securing files so users of account 1, couldn't somehow get to files of account 2?
We're talking Rails if that's a help.
...
I'm developing a new gem (fork of nifty-generators).
Right now my "deployment" consists on the following:
I make changes on the gem's source code
I commit to github
I update the gemspec lower numer (i.e. go from 0.1.1 to 0.1.2)
Build the gem and push it to gemcutter (gem build, gem push)
Install the new gem (sudo gem install mygem)
Th...
Is there any way that I can upgrade my Ruby Gems, and if it doesn't work (on what I'm upgrading them for), than rollback the changes?
...
I can't find where the color_puts would come from in the mod_passenger installer... any ideas?
...
Hi!
First of, im a newbie ruby programmer so please bare with me if this is a very dumb question.
I get this uninitialized constant error when i submit my nested forms.
order.rb
class Order < ActiveRecord::Base
has_many :items, :dependent => :destroy
has_many :types, :through => :items
accepts_nested_attributes_for :items
ac...
I'm working on a Rails application where I have some a set of two radio buttons where users can click "yes" or "no". The MySQL DB column created by the ActiveRecord migration is a tinyint.
If the user doesn't click either radio button I want MySQL to store NULL. (The column allows NULL.) And when they come back to edit the data, neither...
I wrote a program with three methods: def calculate, def compute, and def capture. Each method had some calculations in them. I want to get just the numeric answer of these methods and use them as a response to a question. I'm looking for it to say something like:
Correct, 'calculate answer' and 'compute answer' and 'capture answer'. How...
I have an after_find callback in a model, but I need to disable it in a particular controller action e.g.
def index
@people = People.find(:all) # do something here to disable after_find()?
end
def show
@people = People.find(:all) # after_find() should still be called here!
end
What is the best way to do it?
Can I pass somethin...
Ryan Bates' nifty_scaffolding, for example, does this
edit.html.erb
<%= render :partial => 'form' %>
new.html.erb
<%= render :partial => 'form' %>
_form.html.erb
<%= form_for @some_object_defined_in_action %>
That hidden state makes me feel uncomfortable, so I usually like to do this
edit.html.erb
<%= render :partial => 'form...
I'm writing a ruby bootstrapping script for a school project, and part of this bootstrapping process is to start a couple of background processes (which are written and function properly). What I'd like to do is something along the lines of:
`/path/to/daemon1 &`
`/path/to/daemon2 &`
`/path/to/daemon3 &`
However, that blocks on the fi...
I am new to Ruby, is there a way to yield values from Ruby functions? If yes, how? If not, what are my options to write lazy code?
...
I'm familiarizing myself with some JRuby code, and I'd like to be able to place a breakpoint in the code and run (as usual) from the command-line, having it break into the debugger when it gets to that point. Is there something I can put in my code to force JRuby to break into the debugger?
I've tried running jruby -r debug foo.rb (ins...
In Ruby, the following fails with Errno::ENOENT: No such file or directory, even if the file exists:
open('~/some_file')
However, you can do this:
open(File.expand_path('~/some_file'))
Two questions:
Why doesn't open process the tilde as pointing to the home directory?
Is there a slicker way than using
File.expand_path?
...
I did this:
[User.first, User.last].to_xml
and got this:
<users type="array">
<user>
<created-at type="datetime">2010-03-16T06:40:51Z</created-at>
<id type="integer">3</id>
<password-hash></password-hash>
<salt></salt>
<updated-at type="datetime">2010-03-16T06:40:51Z</updated-at>
<username nil="true">...
Hi There.
How can I make a sticky form in rails?
Thanks
...
Let's say I have two objects: User and Race.
class User
attr_accessor :first_name
attr_accessor :last_name
end
class Race
attr_accessor :course
attr_accessor :start_time
attr_accessor :end_time
end
Now let's say I create an array of hashes like this:
user_races = races.map{ |race| {:user => race.user, :race => race} }
...
While I start server in Fedora 12, a client in Ubuntu 9.10.The client receive this error message.
But it's OK while I start server in Ubuntu 9.10, a client in Fedora 12.
I alreadt shutdown the FireWall.
...