I have a small Ruby script where an array is initialized to hold a few strings
MyArray = ["string 1", "string 2" , "string 2" ]
The problem is that I have quite a few strings in the initialization list and I would like to break the line:
MyArray = [
"string 1"
,"string 2"
,"string 2"
]
...
At some point in my rails development I started making database changes (e.g. dropping or altering columns/tables) without using rails migrations. So now I get errors when I try to deploy my rails app from scratch.
blaine@blaine-laptop ~/tmp/rbjacolyte $ rake db:migrate
(in /home/blaine/tmp/rbjacolyte)
== AddHashToTrack: migrating ====...
I use this to loop the products...
<% form_for :product, @products, :url => { :action => "add_to_cart" } do |f| %>
<%= product.title %>
<%= product.price %>
<%= submit_tag 'Make Order' %>
<% end %>
In my DB, I have
product:
title:abc price:874
title:cde price:98
title:efg price:18
but I can only get the efg 18.0 in my result, I m...
Hi,
I've just upgraded to Win7 x64 Professional and wanted to recommence developing my Rails Apps, however I'm getting the following error :
=> Booting Mongrel
=> Rails 2.3.5 application starting on http://127.0.0.1:3344
D:/nu codes/R/ruby-1.8.7-p174-i386-mswin32/lib/ruby/gems/1.8/gems/rails-2.3.5/lib/initializer.rb:271:in `require_fra...
I'm learning F#, and I'd like to know how a snippet like this could be written using F# only:
2.times {
puts "hello"
}
If you can explain how/if functions that take blocks are possible in F#, that would be great as well.
...
I'm searching for a logging framework for Ruby. Are there any advantages of log4r over the standard Logger class?
...
In order to write more concisely, rather than do this:
test_value = method_call_that_might_return_nil()
if test_value
do_something_with test_value
end
I've been assigning in the conditional:
if test_value = method_call_that_might_return_nil()
do_something_with test_value
end
Is this bad style? The still-more-concise syntax:
do...
Hello there!
I cant find the way to fetch only necessary fields of model in certain context. Let`s say i have a huge model which has about 30 fields (properties). But for a search purpose i need only couple of them.
Example:
class Foo
include DataMapper::Resource
property :id, Serial
property :title, String, :length => 256
p...
In Rails what would be the best way of integrating a UDP listening process that updated certain elements of the model (specifically its going to be adding rows to one of the tables).
The simple answer seems to be start a thread with the UDP socket object within the same process, but its not clear quite where I should even do that which ...
I believe File.foreach('input.txt') would read file one line at a time. Could not fine any documentation on that though. Can anyone confirm that?
Also I wanted to create a gigantic file to test the difference betwween File.forach and File.open . If the file is really large then File.open should fail and File.foreach should succeed. Anyo...
I have been using Rails for over 4 years so obviously I like Rails and like doing things the Rails Way and sometimes I unknowingly fall to the dark side.
I recently picked up Clean Code by Uncle Bob. I am on Chapter 6 and a bit confused whether we as rails developers break the very fundamental rule of OO design, i.e. Law of Demeter or e...
I need to create my own class that extends Hash and append the addictional method to insert to hash my own class variables. Something like this:
class MyHash < Hash
def initialize
super
@local = 0
end
def append_my_data(my_data)
@something@[my_data.id] = my_data
end
end
d = MyHash.new
d.append_my_data(some_var)
p ...
Is there a notion of object-private in any OOP language ?? I mean more restrictive than the classic private access ?
Private (or class-private) restricts the access to the class itself. Only methods that are part of the same class can access private members.
object-private : restricts the access to the object itself. Only methods objec...
I want to start playing with non-relational database, but want something that is popularly used with Rails. I'm considering the ones in the article and leaning towards Voldemort or CouchDB:
http://www.ithighlight.com/2009/07/list-of-companies-powered-by-non-relational-database/
Any recommendations?
...
In rspec (1.2.9), what is the correct way to specify that an object will receive multiple calls to a method with a different argument each time?
I ask because of this confusing result:
describe Object do
it "passes, as expected" do
foo = mock('foo')
foo.should_receive(:bar).once.ordered.with(1)
foo.should_receive(:bar).o...
I have a small plugin for Rails where I add permalinks to my model without storing them (the permalink) in the database (http://github.com/nhocki/make_permalink).
I forked the plugin from a friend and changed the regex, but I don't really know how to make a more friendly and readable regex.
I want to remove all the á, é, í (characters ...
I've been trying to get Thinking Sphinx for Ruby to handle prefixes and/or star, and every time i generate a new configuration file, it seems to ignore it.
Here's the line I added:
define_index do
[... Stuff ...]
set_property :min_prefix_len => 1
end
And then I run:
rake ts:config
rake ts:in
rake ts:run
And nothing new. I ...
Is it better to use obj.nil? or obj == nil and what are the benefits of both.
...
Is there a more concise and idiomatic way to write the following code, which is used to specify default values for optional parameters (in the params/options hash) to a method?
def initialize(params={})
if params.has_key? :verbose
@verbose = params[:verbose]
else
@verbose = true # this is the default value
end
end
I wou...
Windows Vista, Ruby v. 3.3.5
C:\>gem install rmagick
Building native extensions. This could take a while...
ERROR: Error installing rmagick:
ERROR: Failed to build gem native extension.
C:/Ruby19/bin/ruby.exe extconf.rb
checking for Ruby version >= 1.8.5... yes
Invalid drive specification.
Unable to get ImageMagick version
...