ruby

Advanced Array Sorting in Ruby

I'm currently working on a project in ruby, and I hit a wall on how I should proceed. In the project I'm using Dir.glob to search a directory and all of its subdirectories for certain file types and placing them into an arrays. The type of files I'm working with all have the same file name and are differentiated by their extensions. Fo...

Routing problem with calling a new method without an ID

I'm trying to put together a form_tag that edits several Shift objects. I have the form built properly, and it's passing on the correct parameters. I have verified that the parameters work with updating the objects correctly in the console. However, when I click the submit button, I get the error: ActiveRecord::RecordNotFound in Shif...

Ruby: Streaming large AWS S3 object freezes

Hi, I am using the ruby aws/s3 library to retrieve files from Amazon S3. I stream an object and write it to file as per the documentation (with debug every 100 chunks to confirm progress) This works for small files, but randomly freezes downloading large (150MB) files on VPS Ubuntu. Fetching the same files (150MB) from my mac on a much ...

"Personal" method in ruby

I'm looking for a way of making a method "personal" - note NOT PRIVATE to a class here is an example - by "personal" I mean the behaviour of method "foo" class A def foo "foo" end end class B < A def foo "bar" end end class C < B end a=A.new; b=B.new;c=C.new I'm looking for a way of producing the following behav...

Reflection in Ruby. Instantiate an object by given class name

I came to ruby from PHP. How could i do the next thing in ruby? $className = 'ArrayObject'; $arrayObject = new $className(); Thank you for any help! ...

Anyone got SEO tips for Ruby on Rails

Can anyone recommend some RoR plugins and/or general sage that will help me with SEO? ...

Creating has_many relationships in ActiveRecord without :primary_key

I'm working with an older version of Rails and ActiveRecord that does not have the :primary_key option in has_many relationships of more recent ActiveRecord versions and unfortunately I don't get to control when we upgrade. Is there any way to hack this solution via :conditions or :finder_sql options? ...

How to use OptionParse to allow only one flag

There are only three ways to invoke install.sh ./install.sh ./install.sh --force ./install.sh -f I can write it easily. However I am trying to make use of OptionParse. This is what I have so far. def self.parse option = {} optparse = OptionParser.new do |opts| opts.banner = "Usage: ./install.sh [--force]" opts.on...

ordering a collection by an association's property

class Person belongs_to :team class Status #has last_updated property class Team has_many :members, :class => "Person" Ok, so I have a Team class which has many People in it and each of those people has a status and each status has a last_updated property. I'm currently rendering a partial with a collection similar to: =rend...

Is there an equivalent to RSpec's before(:all) in MiniTest?

Since it now seems to have replaced TestUnit in 1.9.1, I can't seem to find an equivalent to this. There are times when you really just want a method to run once for the suite of tests. For now I've resorted to some lovely hackery along the lines of: Class ParseStandardWindTest < MiniTest::Unit::TestCase @@reader ||= PolicyDataReade...

Why is "rake tests" running an empty suite when I use shoulda?

So here is my test suite: class ReleaseTest < ActiveSupport::TestCase should_not_allow_values_for :title, '', 'blah', 'blah blah' should_allow_values_for :title, 'blah - bleh', 'blah blah - bleh bleh' def test_something assert true end end Shoulda's macros generate 5 tests, and then I have test_something below (just to se...

What does it mean to add a hyphen to the closing tag of a ruby loop <% -%>

I'm a noob at this and can't figure out why the hyphen gets added to something like this: <% if flash[:notice] -%> <%= flash[:notice] %> <% end -%> Not even sure if my jargon in the title of this question is accurate. ...

How to use becomes in Rails.

I have a Post Class and a Comment Class. I have a post object and want to convert it to a Comment object. I went through Rails api and found becomes(klass).For now there is not association between a Post and Comment. So i tried @post.becomes(Comment). but becomes method could not be found for @post object. Am i missing something ? ...

How do I add application specific code to Rails' plugin?

Hi, I am using facebooker in one of my applications. I want to add some application specific methods to various classes in it? e.g. In facebooker/lib/facebooker/models/user.rb module Facebooker class User # I want to add my methods here. for e.g my_method end end I can not directly put my_method in the plugin itself since I ...

Is there wsdl to ruby proxy code generators for savon or handsoap gems?

Based on their design philosophy, it sounds like they want gem users to hand code ruby proxy classes. I still feel that they could have provided generators. Any suggestions on how to generate maintainable ruby proxy classes for savon or handsoap? ...

How to disable code completion in NetBeans on Ruby

How do you disable code completion in NetBeans on Ruby? ...

Nested routing in Ruby on Rails

My model class is: class Category < ActiveRecord::Base acts_as_nested_set has_many :children, :foreign_key => "parent_id", :class_name => 'Category' belongs_to :parent, :foreign_key => "parent_id", :class_name => 'Category' def to_param slug end end Is it possible to have such recursive route like this: /root_category...

Why does this Ruby 'if' not behave as expected?

Hey, Im sure I am missing something here but none the less. foo['bar'] = nil if(foo['bar'] == nil) puts "foo bar is nil :(" However, nothing happens? Any thoughts? ...

Rails validation "failing when succeeding"

I have this in my user.rb: attr_accessor :old_password def validate unless password.nil? errors.add_to_base("Old password entered incorrect") unless self.valid_password? old_password end end I have old_password as a a virtual attribute that has to be validated as matching with the current before updating to a ne...

What's with bad function call in view generated via scaffold?

I've scaffolded Things element: script/generate scaffold wip/thing name:string and got some invalid function call in views, like: <td><%= link_to 'Edit', edit_thing_path(thing) %></td> Which raise this error: ActionView::TemplateError (undefined method `edit_thing_path' for #<ActionView::Base:0xb5c00944>) on line #11 of app/views/...