ruby

Access Expression methods in IronRuby

This code works fine in C#: Expression.Lambda(LambdaBody); But none of the methods for building AST seem to visible from IronRuby. I required Microsoft.Scripting.Core and Microsoft.Scripting libraries. Do I need something else? Here is the IronRuby code: require 'C:\reorganize\software\ironruby-1.0rc3\ironruby\bin\microsoft.scripting...

Invalid AuthenticityToken everywhere

I have a rails app that I just deployed which is generating Invalid AuthenticityToken errors anywhere a form is submitted. The app uses subdomains as account names and will also eventually allow for a custom domain to be entered. I have an entry in production.rb to allow for cross-domain session handling. The problem is that you can...

Dynamic Custom Fields for Data Model

I am in the process of creating a dynamic database where user will be able to create resource type where he/she can add custom fields (multiple texts, strings, and files) Each resource type will have the ability to display, import, export its data; I've been thinking about it and here are my approaches. I would love to hear what do yo...

Running Java, Python, Ruby and Perl programs in .NET

I've .NET framework 3.5 installed in my laptop. Just .NET alone, no Visual Studio. How can I run Java, Python, Ruby and Perl programs from the console? Do I need to install something else also, for running these language files? In case there is a need for something extra to be installed and after i have all of them, what are the comma...

Simple neverblock example doesn't work

I'm trying to do something with "neverblock" and I can't seem to get it to work. What I expect: The blocking sleep shouldn't slow down the whole process. I expected to see 5 times "bla" with basically the same timestamp. Ruby: $ ruby --version ruby 1.9.2dev (2010-03-31 trunk 27123) [x86_64-darwin10.2.0] Code: require "neverblock" fi...

Discover the environment and relative path of the running application

Hi, While playing with RubyCocoa, I keep progressing with my idea for my application. Because my application will be going to use configuration files, I would like to know how I discover the relative path to store these inside my application structure (or if a better idea emerges, please elaborate also the "why"). Also good for me to ...

Finding indexes of each element in a multidimensional array in ruby

Eg :a=[["hello", "world"], ["good", "lord"], ["hello", "lord"]] I need to find and record the indexes of each word with respect to the super-array. i.e hello => 0,2 world => 0 lord => 1,2. here's my shot ,but its very amateurish and lengthy. all_tokens=tokens.flatten all_tokens.each do|keyword| ...

Image processing with barehands-ruby

I want to know how to open and manipulate a simple image file in Ruby language. I don't need to do any advanced stuff, just things like open(), get_pixel() and put_pixel() and I don't wanna use any gem for doing that, but just to know the barehands-ruby way. ...

What's causing "NoMethodError: undefined method `include?' for nil:NilClass"

I have a Book model in my Rails application, with various properties (aka columns in the book db table). One of these properties is "ranking". Recently, may app has started to throw NoMethodError: undefined method 'include?' for nil:NilClass for the following code: def some_method(book, another_arg) return book.ranking unless book.ra...

ExtJs Direct with Sinatra

Has anyone used ExtJs Direct functionality with Sinatra? I see ExtJs Direct examples for Merb and Rails, but I haven't found anything which will work with pure Ruby. ...

Rails 3.0.0.beta2 problem with Rails::Generators::GeneratedAttribute

So I am trying to use the rails3 branch of Nifty Generators by Ryan Bates. Now I've used this gem before with beta1 and its worked, but after upgrading to beta2 I've been getting a very wierd error. lib/generators/nifty/scaffold/scaffold_generator.rb:35:in `block in initialize': uninitialized constant Rails::Generators::GeneratedAttrib...

Is strftime (hour) showing wrong time?

I'm using this line to get the beginning time of the first day of the month. t = Time.now.to_date.beginning_of_month.beginning_of_day When i display this using t.strftime("%A %b %e @ %l:%m %p") it shows: Monday Feb 1 @ 12:02 AM The hour is always 12 (instead of 00), and more wierd the minute changes to match the month in inte...

Rails session cookie not getting set

I have a rails app that is a CMS that uses dynamic subdomains for each site. For some reason when I deployed to production the session cookie is not getting set. I'm thinking this is leading to the "Invalid Authenticity Token" errors that are being thrown everywhere. I have my production.rb setup so that I can share sessions across ...

Rails: Mark a class as NOT reloadable

I've got a few classes in lib/ which are not reloadable (due to their internal structure, its a jruby application). How can I tell rails to not reload these after each and every request? Thanks! ...

How to return string name of calling method?

Right now my code works as such: def method_a self.method_b ==> 'method_b' end def method_b puts self.name_of_calling_method end def name_of_calling_method if /`(.*)'/.match(caller.first) return $1 else return nil end end Instead of method_b printing 'method_b', how can I print the name of the calling method -...

Why would Ruby fail equality on 2 floats that appear the same?

Hi there, I have a calculation that generates what appears to be the Float 22.23, and a literal 22.23 like so: some_object.total => 22.23 some_object.total.class => Float 22.23 => 22.23 22.23.class => Float But for some reason, the following is false: some_object.total == 22.23 ? true : false Wacky, right? Is there some kind of p...

Running RSpec on Google App Engine via JRuby

I'm trying to write some tests (RSpec) against the AppEngine and its datastore. I've tried to load the environment and tests via: appcfg.rb run -S spec app/tests/ And I end up with the following error: spec:19: undefined method `bin_path' for Gem:Module (NoMethodError) I can run non-appengine specs just fine by running: spec ...

Validate number of nested attributes

Hello, I have a model with nested attributes : class Foo < ActiveRecord::Base has_many :bar accepts_nested_attributes_for :bar end It works fine. However I'd want to be sure that for every Foo, I have at least two Bar. I can't access the bar_attributes in my validations so it seems I can't validate it. Is there any clean wa...

Building Admin Areas in Rails - General Questions

What is the typical format/structure for creating an administrative area in a Rails application? Specifically I am stumped in the vicinity of these topics: How do you deal with situations where a model's resources are available to both the public and the Admin? i.e. A User model where anyone can create users, login, etc but only the ...

Is there a 'drop to frame' command in the Ruby debugger

The Java debugger has a command called 'drop to frame' that takes you back to the beginning of the current method, resetting the stack as if you had just entered the method call. Static or instance variables won't be reset, but it's still pretty useful for when you stepped over a line and want to try it again. Is there the equivalent in ...