ruby

Has somebody built a navigation/menu helper for Sinatra?

I see there is one for staticmatic, and plenty in the Ruby toolbox for rails menu builders, but I can't seem to track one down specifically for Sinatra. ...

What's a better choice for SQL-backed number crunching - Ruby 1.9, Python 2, Python 3, or PHP 5.3?

Criteria for 'better': fast in math and simple (few fields, many records) db transactions, convenient to develop/read/extend, flexible, connectible. The task is to use a common web development scripting language to process and calculate long time series and multidimensional surfaces (mostly selecting/inserting sets of floats and doing m...

Adding extensions to a stdlib class in a ruby on rails project

Hey, where would I place additions to stdlib classes in a rails project? Let's say something like: class Date def foo 'foo' end end I thought about the initializer folder but it somehow felt wrong. Ideas? ...

Rack, FastCGI, Lighttpd configuration

Hi! I want to run a simple application using Rack, FastCGI and Lighttpd, but I cannot get it working. I get the following error: /usr/lib/ruby/1.8/rack/handler/fastcgi.rb:23:in `initialize': Address already in use - bind(2) (Errno::EADDRINUSE) from /usr/lib/ruby/1.8/rack/handler/fastcgi.rb:23:in `new' from /usr/lib/ruby/1.8/rack/handl...

"Zlib::GzipFile::CRCError crc error" when install gem packages.

[root@blanee local_cache]# gem install dm-core-0.9.11.gem ERROR: While executing gem ... (Zlib::GzipFile::CRCError) invalid compressed data -- crc error [root@blanee local_cache]# gem install ParseTree-3.0.5.gem ERROR: While executing gem ... (Zlib::GzipFile::CRCError) invalid compressed data -- crc error I have a lot gem p...

Common function for self.errors.add_to_base in rails.

In my every model i have 10 or more lines for self.errors.add_to_base. is there any other way i can manage those lines in more easy way? will it possible to manage those errors with some common function which can handle self.errors.add_to_base for any of my model? Function like def error_add_to_base(message,conditions) self.errors...

Throw exception when re-assigning a constant in Ruby?

I've long been aware that "constants" in Ruby (i.e., variable names that are capitalized) aren't really constant. Like other programming languages, a reference to an object is the only thing stored in the variable/constant. (Sidebar: Ruby does have the facility to "freeze" referenced objects from being modified, which as far as I know...

Ruby NameError when referring to Date

I'm getting "uninitialized constant Date (NameError)" with the following code: class Test attr_accessor :reqs def initialize() @reqs = [] end end class TestBuilder def test(&block) @current = Test.new block.call @current end def older_than_days(age) @current.reqs << lambda { |email| ::Date.parse(emai...

create_or_update method in rails

if ClassName.exists?(["id = ?", self.id]) object = ClassName.find_by_name(self.name) object.update_attributes!( :street_address => self.street_address, :city_name => self.city_name, :name => self.org_unit_name, :state_prov_id => self.state_prov_id, :zip_code => self.zip_code) else ClassName.create! :street_address =...

Need suggestion for Ruby and Rails coding standards

I am developing my application using Rails. It has 400 or more models and some models contain more than 200 rows just for relationships, so it's too hard handle it. Are there any ways I can handle my application in more proper and easy ways? ...

Problems Installing Eclipse and Ruby Plugin

I installed Eclipse on my Ubuntu machine and then the Ruby Development Tools (RDT), but it would crash when I try to alter certain features, like having line numbers, how far back to have history, and the code coloring scheme didn't work fully. I decided to try to uninstall Eclipse by doing sudo aptitude remove Eclipse and then sudo apti...

How to read a file from bottom to top in Ruby?

I've been working on a log viewer for a Rails app and have found that I need to read around 200 lines of a log file from bottom to top instead of the default top to bottom. Log files can get quite large, so I've already tried and ruled out the IO.readlines("log_file.log")[-200..-1] method. Are there any other ways to go about reading a...

How add logic to Views? Ruby on Rails

Right now I'm building a project management app in rails, here is some background info: Right now i have 2 models, one is User and the other one is Client. Clients and Users have a one-to-one relationship (client -> has_one and user -> belongs_to which means that the foreign key it's in the users table) So what I'm trying to do it's on...

More ruby-like solution to this problem?

I am learning ruby and practicing it by solving problems from Project Euler. This is my solution for problem 12. # Project Euler problem: 12 # What is the value of the first triangle number to have over five hundred divisors? require 'prime' triangle_number = ->(num){ (num *(num + 1)) / 2 } factor_count = ->(num) do prime_fac = Pr...

Get the value of <option> from views to the controller

Since 'HTML' do not have the attribute 'name',I am looking for a way to accept the value, which I populated in views, in the controller and assign it a variable name for another use. This is sample of my code:` enter code here<form action="<%=url_for(:action =>:make_comment) %>"> <fieldset> <select> <%@category.each {|x|%> <option id="...

Google OpenID-OAuth hybrid implementation on Heroku

Hi, I am looking for a step by step guide to implement Google OpenID+OAuth in our Webapplication running on Heroku for getting calendar/contacts data. I have looked at many documents and Q&A about this but still can't make things work and was wondering if anyone here knew of a place which describes the plugins, gems needed and a step by...

paperclip overwrites / resets S3 permissions for non-bucket-owners

I have opened this as an issue on Github (http://github.com/thoughtbot/paperclip/issues/issue/225) but on the chance that I'm just doing this wrong, I thought I'd also ask about it here. If someone can tell me where I'm going wrong, I can close the issue and save the Paperclip guys some trouble. Issue: When using S3 for storage, and y...

How do you find out what files where changed between commits using Grit

I am having trouble trying to find out what files changed between two different commits. Here is the setup, version of Ruby and the Gem Grit, and what happens when I run the program: > cd /temp > mkdir tt > cd tt > git init Initialized empty Git repository in C:/temp/tt/.git/ > ruby --version ruby 1.8.7 (2010-01-10 patchlevel 249) [i386...

STI and subclasses

Hi All, I want to know, what is a rails way of converting a subclass record to another subclass record, just changing type isn't working and also superclass to subclass and vice versa. Thanks in advance Markiv ...

Use super with before_validation.

I have this code in my every model. Class people def before_validation @attributes.each do |key,value| self[key] = nil if value.blank? end end end Now i want to put my loop in separate module. Like Module test def before_validation @attributes.each do |key,value| self[key] = nil if value.blank? ...