I have a migration in Rails that inserts a record into the database. The Category model depends on this record. Since RSpec clears the database before each example, this record is lost and furthermore never seems to be created since RSpec does not seem to generate the database from migrations. What is the best way to create/recreate thi...
Hi,
I asked a question earlier about which language to use for an AI prototype. The consensus seemed to be that if I want it to be fast, I need to use a language like Java or C++, but that Python / Perl / Ruby would be good for the interface bits.
So, this leads me on to another question. How easy is it to link these languages togethe...
I have a rails template (.rhtml file) generating a Javascript object. It looks something like the following:
var volumes = {
<% for volume in @volumes %>
<%= volume.id %> : <%= volume.data %>
<%= ',' unless volume === @volumes.last %>
<% end %>
};
Note the unless statement modifier to suppress printing the comma after the...
I want to deal with the command line input in Ruby:
> cat input.txt | myprog.rb
> myprog.rb < input.txt
> myprog.rb arg1 arg2 arg3 ...
What is the best way to do it? In particular I want to deal with blank STDIN, and I hope for an elegant solution.
#!/usr/bin/env ruby
STDIN.read.split("\n").each do |a|
puts a
end
ARGV.each do |b...
I recently had to extend the aasm states for the latest version of restful_authentication (github) in one of my apps. I removed the "include Authorization::AasmRoles", copied the existing states and events from the plugin and made the changes necessary to support an additional "published" state on my account model.
Does anyone have a cl...
I can't seem to get a scrollbar to work in an inner stack/flow. Does anyone know how to?
...
searchterms.rb
search = "1|butter+salted|Butter salt|Butter|Túrós csusza|Margarine|Potato
2|butter+whipped|Shea butter|Butter|Pastry bag|Cream bun|Butter cream
3|butter+oil+anhydrous|Ultralight backpacking|Odell\'s|Ghee|Fragrance extraction|Perfume
4|cheese+blue|Blue cheese|Shropshire Blue cheese|Buxton Blu...
I want to be able to compare Dates and Times in Rails without always having to call the to_time or to_date method. So I wrote the following code:
class Date
def ==(other)
if other.kind_of?(Time)
self.to_time == other
else
super(other)
end
end
end
I know there's an easy way to write this so that I can make t...
I'm finally getting the hang of RSpec after spending a couple of hours over the weekend. Now I'm stuck trying to figure out how to assert that parameters are indeed passed into the controller. I'm following the Bowled over by Ruby/Cocoa example and adapting it for the iPhone SDK. I've done a more detailed writeup of my progress on my blo...
I'm looking for a method to reliably extract the host name from a URL string in Ruby.
e.g.
http://www.mglenn.com/directory = www.mglenn.com
OR
http://www.mglenn.com?param=x = www.mglenn.com
...
Which style of Ruby string quoting do you favour? Up until now I've always used 'single quotes' unless the string contains certain escape sequences or interpolation, in which case I obviously have to use "double quotes".
However, is there really any reason not to just use double quoted strings everywhere?
...
I came in this morning, fired up my app in the same way as usual, and started getting this error. Since then, I have been down every road I can conceive - to the point of removing and reinstalling every piece of ruby/rails software on my machine, including mysql. I have stripped my application down to just the following.
require 'ruby...
How do you convert between a DateTime and a Time object in Ruby?
...
I'm trying to use Shoes' download() method to pass a username and password in the HTTP header to authenticate the HTTP request (talking to a Rails app).
I'm a bit of a newb when it comes to this stuff.
I havn't quite understood whether I should be automatically able to use the below syntax (username:pwd@) or whether the username and p...
I've used straight Mongrel, I've used Mongrel clusters behind Apache, I've looked at Thin, and I'm becoming very intrigued by Passenger. I've looked at Nginx, too. I've looked at MRI, Ruby Enterprise Edition, Rubinius, and JRuby. There are a lot of options, each claiming to be the new holy grail.
What is the best option out there for a ...
Hi all, my first question here.
Let say I have the following code in application_helper.rb
def do_something
if action_name == 'index'
'do'
else
'dont'
end
end
which will do something if called within index action
Q: How do I rewrite the helper spec for this in application_helper_spec.rb to meet simulate a call from 'index'...
I'm making a simple script using ruby on a Windows 2003 Server.
My questions are:
How can I connect to a database through ODBC? I will be connecting to both Sybase on Solaris and MSSQL Server.
How can I send emails through an Exchange Server 2003?
Update
What's the best simple IDE for Ruby scripting? I currently use SciTE (whic...
Hi all there,
I have a loop (for item in @dataset) and I want, in each iteration, to get different data from another table and make some operations that will be printed in the view. I cant't get this data from the dataset used in the loop.
How can I do this according to MVC? I can put the code into the loop, in the view, but I think it...
I'm trying to do Ruby password input with the Highline gem and since I have the user input the password twice, I'd like to eliminate the duplication on the blocks I'm passing in. For example, a simple version of what I'm doing right now is:
new_pass = ask("Enter your new password: ") { |prompt| prompt.echo = false }
verify_pass = ask("E...
So with ruby being ushered in as the new programming messiah, I'm wondering if anyone has preferences based upon ease of use, resources needed to run, usability and ease of customization.
is there a better of the two?
...