Hello,
I have two models: (1) Task, and (2) CompletedTask.
I'm looking to do a named_scope for :incomplete_tasks (tasks that don't have any entries in the completed_tasks table)
I'm thinking it would be something like this in my Task model:
named_scope :incomplete_tasks, :conditions => **completed_tasks.empty?**
Do you know how I f...
parent = ["A","B","C",["a","b", "c", "d"], "D"]
parent.each do |children|
if children.is_a?
children.flatten # how do i insert it back to parent
# so that this loop can continue looping through the remainder
#including the newly flattened children(a,b,c,d)
end
end
The question is, once an array is discovered, i flatten it, and nee...
Good friends of stackoverflow, I am here today for guidance regarding image processing/manipulation using Ruby in a Rails environment. I'm creating on-the-fly dynamic banner ads that will feature mostly (if not completely) text. It's fairly simple with just a line or two, but I'd like the option to adjust font, text color, text size, etc...
how can i substitue an element's array ?
a = [1,2,3,4,5]
i need to replace 5 with [11,22,33,44].flatten!
so that a now becomes
a = [1,2,3,4,11,22,33,44]
...
Essentially, my route is working perfectly, Passenger seems to be loading - all is hunky-dory. Except that nothing Railsy happens. Here's my Nginx log from starting the server to the first request (ignore the different domain/route - it's because I haven't moved the new domain over yet, and it's returning a 403 error because there's no i...
Hello,
I was writing a small Heap implementation and upon creating my Node class I noticed some weird behaviour. I wanted to call defined?(x) to ensure x was defined, then check if x was an Integer, before storing it in the Node's value class variable. In IRB I can call
defined?(x) and the result is nil.
However, in the class, I try th...
I'm working on a web application right now using Rails and wanted to see if anyone knew of a good way to keep track of file storage limits? We want to give users a specific amount of room that they can use to upload files and we are using paperclip for storage on Amazon S3. Any thoughts? Thanks
...
Hi,
I try to parse RSS chaanal with simple-rss lib.
Unfortunately I got a lot of garbage in node:
<description><p>
some decryption
</p>
<a href="http://url.com/trac/xxx/wiki/foo?action=diff&amp;amp;version=28"&gt;(diff)&lt;/a&gt;</description>
I need to retrieve text ("some description") and o...
I'm trying to build a script to go through my original, high-res photos and replace the old, low-res ones I uploaded to Flickr before I had a pro account.
For many of them I can just use Exif info such as date taken to determine a match. But some are really old, and either the original file didn't have Exif info, or it got clobbered by ...
I'm wondering how a one can use Bundler with Sinatra. The idea is to use the gems that Bundler downloads inside the .gems folder.
...
Is there any Array or Enumerable built-in that allows me to search for an element using a block, and return its index?
Something along the lines of :
ar = [15,2,33,4,50,69]
indexes = ar.find_indexes {|item| item > 4 == 0}
# indexes will now contain 0,2,4,5
It would be very easy to add my own, but I'd like to know if this already exis...
Is this the most efficent way to forward the 'each' call to the Hash's native each method.
Should I make @index visible to the outside?
I'm a bit unsure as a block is invovled.
class TimeSlice
def initialize(list)
# @index is a hash
@index = list.do_some_magic()
end
def each(&block)
@index.each(&block)
end
end
...
How do I get only first (say) 200 characters from my object Article (which is in a table articles with aattributes content and title)?
Thank you
...
Given this code:
a = {1=>2}
m = a.method(:[])
I know that I can now use :
value = m.call(1)
and it will return 2. The thing is, what do I need to change so that I can call the method directly like :
m.call()
and it will get the 1 sent as a parameter? It would be nice to be able to write something like :
m = a.method(:[],1) # wh...
I've been using Selenium (with selenium rc, and the ide) in ruby, with rspec, for some time and it's been great. I recently wiped my installation of ubuntu, however, and installed ubuntu 9.10. I set selenium up again, which consisted of installing the selenium-client gem (1.2.17) and adding the selenium ide plugin in firefox.
When i r...
I'm trying to test output from a command line tool. How do I 'fake' a command line call with rspec? Doing the following doesn't work:
it "should call the command line and return 'text'" do
@p = Pig.new
@p.should_receive(:run).with('my_command_line_tool_call').and_return('result text')
end
How do I create that stub?
...
Class A and B are identical:
class A < ActiveRecord::Base
def foo
puts "foo"
end
end
class B < ActiveRecord::Base
def foo
puts "foo"
end
end
What's the difference between refactoring like this with a base class:
class Base < ActiveRecord::Base
def foo
puts "foo"
end
end
class A < Base
end
class B < Base
end
versus li...
i am testing an application built with rails and from time to time get bugs
when it happens, ActionView::TemplateError occurs and gets logged in log/production.log
how do i catch it and f.ex. send myself by email whenever it happens somewhere in the app?
what is the best way to do that?
f.ex. in ApplicationController with some sort o...
Hi I use this parser for my project: http://simple-rss.rubyforge.org/
It works nice but I have nodes like this:
<dc:creator>viroos</dc:creator>
I have no idea how to get nodes like this.
...
Hi there, I have a text log from a game with (for example) two types of entries viz. Chat and Event. For the most part they are very similar so I have a LogEntry class defined as so;
class LogEntry < Array
def initialize(str)
super str.split
end
def parse
LogEntry.parse self
end
def LogEntry.parse(entry)
# Proc...