I needed to fix the encoding of an ActiveRecord attribute and decided to do it in a before_save hook. And at this point I noticed an unexpected feature. When I wanted to change the value of the attribute, simple using the attribute_name=XY did not work as I expected. Instead of that I needed to use self[:attribute_name]=XY. So far did no...
Given a collection of named Foos from ActiveRecord, why does Array#include? not seem to call Foo.== but yet index does?
class Foo < ActiveRecord::Base
def ==(s)
self.name == s
end
end
class Bar < ActiveRecord::Base
has_many :foos
end
bar.foos << Foo.new( :name => 'hmm' )
bar.foos.all.include?('hmm') # does select all from ...
In my case,
I was storing the sql query in my database as text.
I am showing you one record which is present in my database
Query.all
:id => 1, :sql => "select * from user where id = #{params[:id]}"
str = Query.first
Now 'str' has value "select * from user where id = #{params[:id]}"
Here, I want to parsed the string like
If my pa...
Hi. I found this answer and it sounds like almost exactly what I'm doing. I have heard mixed answers about whether or not datamapper can support SQL Server through dataobjects. Basically, we have an app that uses a consistently structured database, consistently named tables, etc in SQL Server. We're making all kinds of tools and stuff th...
I'm using my MOO project to teach myself Test Driven Design, and it's taking me interesting places. For example, I wrote a test that said an attribute on a particular object should always return an array, so --
t = Thing.new("test")
p t.names #-> ["test"]
t.names = nil
p t.names #-> []
The code I have for this is okay, but it doesn...
Are there any graph database in ruby . i have heard of neo4j in Jruby , Are there any pure implementation of graph database in ruby ?
...
Are there any scripts out there, or have any of you built a tool, to convert YAML to XML using Nokogiri? If not, any suggestions or samples?
...
I need to generate formatted text packing slips for a Ruby on Rails project I'm working on. I'm considering using Ruport or just formatting it myself in a string and outputting it to text. The only challenge is justifying all of the output appropriately. It needs to look something like this, always aligned properly. Any recommendations?
...
I need to create a simple webservice in C# but I'm not sure where to start (I've coded UI apps in C# before but all my web experience is in Ruby on Rails). Where do I start?
The only client for the webservice will be a Ruby on Rails app so there's no need for any HTML rendering. I was thinking of just returning a XML or YAML formatted s...
I'm going crazy: Where is the Ruby function for factorial? No, I don't need tutorial implementations, I just want the function from the library. It's not in Math!
I'm starting to doubt, is it a standard library function?
...
In Ruby i do so
asd = 123
asd = '%b' % asd # => "1111011"
...
I have 4 string variables name, quest, favorite_color, speed that might be empty. I want to concatenate them all together, putting spaces between those that aren't empty.
So:
name = 'Tim'
quest = 'destroy'
favorite_color = 'red'
speed = 'fast'
becomes
'Tim destroy red fast'
and
name = 'Steve'
quest = ''
favorite_color = ''
speed...
We have server on Python and client + web service on Ruby. That works only if file from URL is less than 800 k. It seems like "socket.puts data" in a client works, but "output = socket.gets" - not. I think problem is in a Python part. For big files tests run "Connection reset by peer". Is it buffer size variable by default somewhere in a...
I want to be able to do Artist.case_insensitive_find_or_create_by_name(artist_name)[1] (and have it work on both sqlite and postgreSQL)
What's the best way to accomplish this? Right now I'm just adding a method directly to the Artist class (kind of ugly, especially if I want this functionality in another class, but whatever):
def sel...
I have a three-level multi-nested form in Rails. The setup is like this: Projects have many Milestones, and Milestones have many Notes. The goal is to have everything editable within the page with JavaScript, where we can add multiple new Milestones to a Project within the page, and add new Notes to new and existing Milestones.
Everythi...
Hello,
Besides using Appcelerator's Titanium Desktop, are there other approaches to integrating Javascript and Ruby/Python into cross-platform desktop applications? Just trying to get a sense of the landscape here. From searching the web, it seems Titanium may be leading the charge in terms of this type of integration. I wasn't able ...
Hi, I recently installed jruby on a machine that also has ruby installed on it. When I do
rake something it now appears to be using the jruby interpreter. I'd like rake to use the ruby interpreter. I'd appreciate any help.
...
I want to implement a feature like in twitter where when new tweets show up the title changes. How to display the record when the record has just been created.
...
I have a ruby script that does a few perforce operations (through the scripting API) then simply ends:
def foo()
...
end
def bar()
...
end
foo()
bar()
puts __LINE__
exit 0
#end of file
...and while the LINE will print out, the process never ends, whether the exit(0) is there or not. This is ruby 1.8.6, primarily on the mac, but...
I have a simple script that does some search and replace.
This is basically it:
File.open("us_cities.yml", "r+") do |file|
while line = file.gets
"do find a replace"
end
"Here I want to write to a new file"
end
As you can see I want to write a new file with the output. How can I do this?
...