When using before_filter :login_required to protect a particular page, the link_to_unless_current method in the application layout template renders the "Login" link for the login page as a hyperlink instead of just text.
The "Login" text/link problem only occurs when redirected to the Login Page via the before_filter machinery, otherwis...
I have a controller method that returns a list for a drop down that gets rendered in a partial, but depending on where the partial is being used, the RJS template needs to be different. Can I pass a parameter to the controller that will determine which RJS gets used?
Here is the controller method, it is very simple:
def services
res...
Ruby can add methods to the Number class and other core types to get effects like:
1.should_equal(1)
But it seems like python cannot do this. Is this true? And if so, why? Does it have something to do with the fact that type can't be modified?
Update: Rather than talking about different definitions of monkey patching, I would like t...
I would like to get source for a small, well written rails app to modify and "play with" as I learn how to program. I have found hundreds of open-source apps, but I don't know which are any good.
Any suggestions?
...
Hi,
I want to use shoes to be able to download the body of a website that a user enters in an edit_line. How can I make this work? Can anyone help explain why the below code does not work? It just pops up a new window, and does not download the site from the text entered....
Here's my code thus far:
Shoes.app do
stack (:left => 1...
I'm writing a Rails application, but can't seem to find how to do relative time, i.e. if given a certain Time class, it can calculate "30 seconds ago" or "2 days ago" or if it's longer than a month "9/1/2008", etc.
...
I'm experimenting with the iPhone SDK and doing some TDD ala Dr. Nic's rbiPhoneTest project. I'm wondering how many, if any, have been successful using this or any other testing framework for iPhone/Cocoa? More important, I'd like to know how to best assert a proprietary binary request/response protocol. The idea is to send a binary requ...
I need to be able to send encrypted data between a Ruby client and a Python server (and vice versa) and have been having trouble with the ruby-aes gem/library. The library is very easy to use but we've been having trouble passing data between it and the pyCrypto AES library for Python. These libraries seem to be fine when they're the onl...
In Python, you can do this:
print "Hi! I'm %(name)s, and I'm %(age)d years old." % ({"name":"Brian","age":30})
What's the closest, simplest Ruby idiom to replicate this behavior? (No monkeypatching the String class, please.)
EDIT: One of the really excellent benefits of this is that you can store the pre-processed string in a varia...
How can I do the Ruby method "Flatten" Ruby Method in C#. This method flattens a jagged array into a single-dimensional array.
For example:
s = [ 1, 2, 3 ] #=> [1, 2, 3]
t = [ 4, 5, 6, [7, 8] ] #=> [4, 5, 6, [7, 8]]
a = [ s, t, 9, 10 ] #=> [[1, 2, 3], [4, 5, 6, [7, 8]], 9, 10]
a.flatten #=> [1, 2, 3, 4...
I want to do some checking in a writer accessor. My first idea was returning a boolean.
class MyClass
def var=(var)
@var = var
# some checking
return true
end
end
m = MyClass.new
retval = (m.var = 'foo')
=> "foo"
Can I set a return value in a writer accessor? If yes, how can I get this value?
...
In Ruby, how do you generate a random number between 0 and n? In .NET you can create a Random object, does something like this exist for Ruby?
...
In a project which uses restful_authentication with acts_as_state_machine and email activation, I get a double render error whenever a user does the activation action from the email link.
I'm using the default
def activate
self.current_user = params[:activation_code].blank? ? false : User.find_by_activation_code(params[:activation_c...
I'm building an app in Ruby on Rails, and I'm including 3 of my models (and their migration scripts) to show what I'm trying to do, and what isn't working. Here's the rundown: I have users in my application that belong to teams, and each team can have multiple coaches. I want to be able to pull a list of the coaches that are applicable...
So $0 is the env variable for the top level Ruby program ... but is there one for the current method?
...
I want to be able to write a lambda/Proc in my Ruby code, serialize it so that I can write it to disk, and then execute the lambda later. Sort of like...
x = 40
f = lambda { |y| x + y }
save_for_later(f)
Later, in a separate run of the Ruby interpreter, I want to be able to say...
f = load_from_before
z = f.call(2)
z.should == 42
...
Is there a .NET Framework compiler for the Ruby language? I've heard of the DLR (Dynamic Language Runtime), is this going to enable Ruby to be used with .NET development?
...
I have a SOAP client in Ruby that I'm trying to get working with a Ruby SOAP server, to no avail. The client works fine over SSL with a Python SOAP server, but not with the Ruby version. Here's what the server looks like:
require 'soap/rpc/standaloneServer'
require 'soap/rpc/driver'
require 'rubygems'
require 'httpclient'
def cert(file...
I'm trying to create a use-once HTTP server to handle a single callback and need help with finding a free TCP port in Ruby.
This is the skeleton of what I'm doing:
require 'socket'
t = STDIN.read
port = 8081
while s = TCPServer.new('127.0.0.1', port).accept
puts s.gets
s.print "HTTP/1.1 200/OK\rContent-type: text/plain\r\n\r\n" + t...
I'm creating a bunch of migrations, some of which are standard "create table" or "modify table" migrations, and some of which modify data. I'm using my actual ActiveRecord models to modify the data, a la:
Blog.all.each do |blog|
update_some_blog_attributes_to_match_new_schema
end
The problem is that if I load the Blog class, then m...