I have a database full of text fields that look like this:
(paragraph of normal text)
image:blog/clownboy.jpg
(another paragraph)
I'm trying to write a view helper for Rails that will take one of these big blocks of text, find bits like "image:blog/clownboy.jpg" and replace them with the corresponding <img src="blog/clownboy.jpg"> (...
I've run into this dilemma several times. Should my unit-tests duplicate the functionality of the method they are testing to verify its integrity? OR Should unit tests strive to test the method with numerous manually created instances of inputs and expected outputs?
I'm mainly asking the question for situations where the method you are...
use Rack::Static, :urls => ['/stylesheets', '/images'], :root => 'public'
run proc { |env| [200, { 'Content-Type' => 'text/html', 'Cache-Control' => 'public, max-age=86400' }, File.open('public/index.html')] }
I get private method `open' called for Rack::File:Class when I rackup. Really can't see where the problem is. Running rack 1....
hello,
i want to learn rails and as a project to learn rails i came across webquests. what a webquest is is clearly written here1 and this is a example how a webquest look like.
i started with script/generate nifty_scaffold introduction index and repeat this for every section like task , Process, Evaluation and so on. but i dont think ...
Hello,
I'm trying, for the first time, to create a GUI in Ruby using Tk. I've copied a code snippet from one of the numerous web tutorials and try to change the font for one of the labels, but nothing seems to affect how the text is presented.
Here's the code:
require 'tk'
root = TkRoot.new('title'=>'MCIS')
defaultFont = TkFont.new(...
I'm trying to write a rails application where users can upload images, but Paperclip doesn't seem to be working for me.
I've gone through all the basic steps (added has_attached_file, the migration, making the form multipart) but I keep getting the same error whenever I try uploading an image:
can't convert nil into Integer
Lookin...
Hi i have a yaml file like so
---
data:
- date: "2004-06-11"
description: First description
- date: "2008-01-12"
description: Another descripion
How can i do a "ypath" query similar to xpath for xml ? Something like "get the description where the date is 2004-06-11"
YAML.parse_file('myfile.yml').select('/data/*/date == 2...
Tell why you think Python, Perl, Ruby, etc is easiest for plugging in modules from other languages with minimal thought.
To clarify, an example: I want to write business logic in Python, but use functionality that conveniently exists as a Perl module.
In other words, which language "just works" with the most modules?
...
I notice that I am getting very poor performance for either or both inserts and queries. The queries themselves are basic and can execute with no delay directly from mysql. The ruby script that I wrote is only 1 thread, so only 1 connection is being used, and never closed unless the script is terminated. Pretty basic, I am just trying to...
Hey there,
I am trying to write a simple function to clean a filename string and update the object. When I save a test string it works, but when I try to save the string variable I've created, nothing happens. But when I return the string, the output seems to be correct! What am I missing?
def clean_filename
clean_name = file...
I know python has a py2app, I was wondering if Ruby has anything like that. I know there is OCRA for windows, but what about for OS X?
...
I'm struggling with a strange issue. According to http://github.com/sinatra/sinatra (secion Filters) a response object is available in after filter blocks in Sinatra 1.0. However the response.status is correctly accessible, I can not see non-empty response.body from my routes inside after filter.
I have this rackup file:
config.ru
req...
I have an nested model student that belongs to a high_school. The problem is that when I go to create a new student (/high_schools/1/students/new) I get this error:
No route matches {:action=>"destroy", :controller=>"students", :high_school_id=> # <HighSchool id: 1, name: "cool place", ... }
<%= form_for @student, :url => high_school_...
In my messages_controller I have the following private method:
def find_message_or_404(slug)
message = user.messages.find_by_slug(slug)
if message.nil?
raise Error404
end
message
end
I find it not elegant and not very Rubist. Is there a way to improve it?
...
In Python, if I want to get the first n characters of a string minus the last character, I do:
output = 'stackoverflow'
print output[:-1]
What's the Ruby equivalent?
...
I've written this class that returns feed updates, but am thinking it can be further improved. It's not glitchy or anything, but as a new ruby developer, I reckon it's always good to improve :-)
class FeedManager
attr_accessor :feed_object, :update, :new_entries
require 'feedtosis'
def initialize(feed_url)
@feed_object = Fee...
Hi,
I am trying out Mongrel and using the following code:
require 'rubygems'
require 'mongrel'
class SimpleHandler < Mongrel::HttpHandler
def process(request, response)
response.start(200) do |head, out|
head["Content-Type"] = "text/plain"
out.write("Hello World!\n")
end
end
end
h = Mon...
Question is, are state machines always defined statically (on classes)? Or is there a way for me to have it so each instance of the class with has it's own set of states?
I'm checking out Stonepath for implementing a Task Engine. I don't really see the distinction between "states" and "tasks" in there, so I'm thinking I could just map...
In Ruby, there's Modules and you can extend a class by "mixing-in" the module.
Module myModule
def printone
print "one"
end
end
Class myClass
extend myModule
end
theOne = myClass.new
theOne.printone
>> one
In Objective-C, I find that I have a set of common methods that I want a number of Class to "inherit". What other wa...
I'm searching for a tool that will take a source directory and produce a single PDF containing the source code, preferably with syntax highlighting.
I would like to read the PDF on my phone, in order to get familiar with a code-base, or just to see what I can learn by reading a lot of code. I will most often be reading Ruby.
I would pr...