ruby

Date validations

Hi guys i am having a problem of validating the date if it's wrong.e.g if i search for a record in the database for 31 february it only show me the error in the server, and it doesn't display anything..i dont have a clue what to do help please... my code for storing my hash date is @start = "#{params[:start][:day]}-#{params[:start][:mon...

Thinking Sphinx - Delta indexing doesn't work

In my app, I need every new record to be added to the index instantly (not after rake ts:index). If I understand it correctly delta indexing is what I'm looking for. So, I added delta column to every table I'm indexing with Sphinx, set the default value to false and added set_property :delta => true to every define_index block; then ran ...

While processing an email reply how can I ignore any email client specifics & the history?

I have a rails application which processes incoming emails via IMAP. Currently a method is used that searches the parts of a TMail object for a given content_type: def self.search_parts_for_content_type(parts, content_type = 'text/html') parts.each do |part| if part.content_type == content_type return part.body e...

Does Ruby perform Tail Call Optimization?

Functional languages lead to use of recursion to solve a lot of problems, and therefore many of them perform Tail Call Optimization (TCO). TCO causes calls to a function from another function (or itself, in which case this feature is also known as Tail Recursion Elimination, which is a subset of TCO), as the last step of that function, t...

How to create a sortable interface with 'acts as nested set' in RubyOnRails

I've been implementing some nice interactive interfaces that can sort lists in my m rails app for models that use acts_as_list. I have a sort function that gets called and sets the position for each record afterr each drag and drop using the sortable_element script.aculo.us function. This is an example of the controller action that han...

Where to put ruby .gem files so that Shoes.setup can find them?

A lot of questions have been asked about gem support in Shoes, but none have answered where to put them. I've got Shoes Raisins 1134 on Windows XP, and I've downloaded dbi-0.4.1.gem and am trying to get the following to work: Shoes.setup do gem 'dbi' end require 'dbi' Shoes.app ... end When I run this, I get the dialog that sa...

Rails ActiveRecord - is there a way to perform operations on tables without an id?

I have a table with one row and two columns- int 'version', datetime 'updated' Is there a Rails ActiveRecord way to get and set the data in these columns? There is no id column. I'm using this table to track versions of queries of other tables. After each query of another table the version column is incremented and the updated colum...

How do I pass command line arguments to a rake task?

I've got a rake task that I am making that needs to insert a value into multiple databases. I'd like to be able to pass this value into the rake task from the command line, or from another rake task, how can I do this? ...

How do I get the name of a Ruby class?

How can I get the class name from an ActiveRecord object? I have: result = User.find(1) I tried: result.class # => User(id: integer, name: string ...) result.to_s # => #<User:0x3d07cdc>" I need only the class name, in a string (User in this case). Is there a method for that? I know this is pretty basic, but I searched both rails' ...

What's the best way to extract Excel cell comments using Perl or Ruby?

I've been parsing Excel documents in Perl successfully with Spreadhsheet::ParseExcel (as recommended in http://stackoverflow.com/questions/429193), but I can't figure out how to extract cell comments. Any ideas? A solution in Perl or Ruby would be ideal. ...

How to consume JSON formatting with ruby's ActiveResource?

ActiveRecord introduced a change to its default JSON output format. It went from { "user": { some_junk } } to { some_junk } ActiveResource has apparently followed their lead, expecting to consume JSON as { some_junk } I am trying desperately to consume a RESTful web service which emits { "user": { some_junk } } Is there a w...

When do Ruby instance variables get set?

class Hello @hello = "hello" def display puts @hello end end h = Hello.new h.display I created the class above. It doesn't print anything out. I thought the instance variable @hello was set during the class declaration. But when I call the display method the output is 'nil'. What's the correct way to do this? ...

Microsoft SQL Server Statistics via ODBC

I have an instance of SQL Server that I am trying to benchmark. From the SQL Studio application I can type SET STATISTICS TIME ON and see outputted statistics after that. From C++ code, I can do something like SQLExecDirect(hstmt, "SET STATISTICS TIME ON", SQL_NTS); and then retrieve these statistics via SQLError. Is there a way t...

Provide feedback to view from controller in ruby on rails

I am using multiple file field in a view to upload multiple files. I would like to update the user of progress while uploading. I tried using something like this def create params[:upload_data].each do |file| unless (file =="" or file== nil) @photo = Photo.create({:approved => false, :user_id => @current_user.id}) ...

Ruby spaceship operator <=>

What is the Ruby spaceship operator? Is the operator implemented by any other languages? ...

booleans in rails with sqlite

I am a bit of a noob still with rails, but I am running across something that seems a bit odd. I added a boolean field to a model in the database thusly t.column :admin, :bool, :default => false, :null => false However, the value in the sqlite3 database seems to be either 't' or 'f'. That is fine, but I would still expect user.admin? ...

Unable to install gem

I am getting this error, when trying to install any gem ERROR: http://gems.rubyforge.org/ does not appear to be a repository But when I do gem sources, it shows * CURRENT SOURCES * http://gems.rubyforge.org/ ...

AR Mailer with changing settings?

Hi we're running ARMailer in one of our projects right now. It's working fine but as different customers are allowed to send confirmation emails via this service we want to offer them the possibility to use their own SMTP settings for that. Is there a way to change ARMailer settings on the fly? Or is there an ARMailer alternative mayb...

problems with mysql for ruby on rails

Hello, ah...it is not easy to get started ruby on rails to me.. I am trying to use mysql for ruby on rails development. When I execute "gem install mysql", I get following error. error: while generating documentation for mysql-2.8.3-x86-mswin32...message: unhandled special: special: type=17...bla bla... how do I install mysql for ru...

Nokogiri: Sort Array of IDs according to order in HTML document.

I have an unsorted Array holding the following IDs: @un_array = ['bar', 'para-3', 'para-2', 'para-7'] Is there a smart way of using Nokogiri (or plain Javascript) to sort the array according to the order of the IDs in the example HTML document below? require 'rubygems' require 'nokogiri' value = Nokogiri::HTML.parse(<<-HTML_END) ...