ruby

Thinking Sphinx and lack of updated records

We are running thinking sphinx on a utility instance in our server cluster. It is rerunning the index every minute. But, if you make a change to a record, it disappears from search results until the index is updated (up to 1 minute). Is Thinking Sphinx only returning rows that have updated_at times that less than their last index? If...

Ruby - Sending email example code problem

Hi, i´m trying to send an email from ruby but I get an error msg. I have this code: require 'net/smtp' message = <<MESSAGE_END From: Private Person <[email protected]> To: A Test User <[email protected]> Subject: SMTP e-mail test This is a test e-mail message. MESSAGE_END Net::SMTP.start('smtp.test.net', 25, 'test.com', 'usr', 'pwd'...

how to use erb to output file after binding

Hi, I got the following example: require 'erb' names = [] names.push( { 'first' => "Jack", 'last' => "Herrington" } ) names.push( { 'first' => "LoriLi", 'last' => "Herrington" } ) names.push( { 'first' => "Megan", 'last' => "Herrington" } ) myname = "John Smith" File.open( ARGV[0] ) { |fh| erb = ERB.new( fh.read ) print erb.result...

Problem in making custom syntax highlighting in TextMate. Help!

Hi, I am trying to highlight a custom language in TextMate. However, the following definition does not highlight PHP insertions (I do select it for my *.serpent files): { scopeName = 'source.serpent'; fileTypes = ( 'serpent' ); patterns = ( { begin = '<\?'; end = '\?>'; patterns = ( { include = 'source.php'; } ); }, ); } ...

Clean way to assign value unless empty

Hello, I often need to assign a variable, if the source value is set. So far I have done it like this: filters[:red] = params[:search][:red] unless params[:search][:red].nil? This works but looks a bit clumsy. There must be a more DRY way of getting this result. Any suggestions? Best regards. Asbjørn Morell. ...

[Ruby] Confirm existance of executable (script, bat, cmd, exe) via a ruby file.

Using a ruby file (or any rake facility) I need to find out if the user who executes my script is able to execute certain shell commands. In particular g++ etc. Hopefully system independent so if there is some g++.bat, g++.exe or just g++ (etc) it should say yes nevertheless, as long as its on the path and executable on the users system....

rack variables not showing up

rack.request.form_input isn't in my env variable--what's going on? anyone?? ...

activemessaging with stomp and activemq.prefetchSize=1

I have a situation where I have a single activemq broker with 2 queues, Q1 and Q2. I have two ruby-based consumers using activemessaging. Let's call them C1 and C2. Both consumers subscribe to each queue. I'm setting activemq.prefetchSize=1 when subscribing to each queue. I'm also setting ack=client. Consider the following sequence...

case insensitive search in rails - an example from Beginning Rails

Hi, Could some on help me to turn the following search into case - insensitive? Here is the piece of code for earching "title" field in event module: # Add each field to the conditions array searchable_fields.each_pair do |field, value| conditions << "#{field} LIKE ?" values << "%#{value}%" end Here is the data I have entered: ...

Within a category, "Seach all posts" checkbox, how to?

Hi, I have set up my routes so I can search all posts with: /posts/search/foobar or search inside a category /posts/category/1/search/foobar It works pretty well, when someone is browsing an specific category it does search just posts that belongs to that category. When inside a category, I want to place a checkbox to "Search all...

Ruby , Parsing an XML Document, How can i print the number of subtags for a given tag

ref xml doc I want to parse on EACH <HOST> and get the number of <OID> , along with Values of each <TYPE> <HOST> <IP>10.1.3.1</IP> <TRACKING_METHOD>IP</TRACKING_METHOD> <DNS><![CDATA[.demo.com]]></DNS> <OPERATING_SYSTEM><![CDATA[abcd Version 7]]></OPERATING_SYSTEM> <ASSET_GROUPS> <ASSET_GROUP_TITLE><![CDATA[Demo Lab ]...

Tagging a user in Open Graph API using Ruby

Hello, I have found some really sparse documentation about the options for posting to your feed. I am trying to post to "/me/feed" and then include a user in that post. I am trying to re-create the way that you can now do @username in the Facebook Status box, but from the API instead. Using the Ruby OAuth2 lib I to do the following. ...

Ruby/Rails question about locating help/definitions w/in the system

This is probably super basic but, well, I can't find it... What's the best way to explore Rails from within the installation itself. Let me explain. I'm looking at some Migration code and curious what a symbol means. How/where do I look that up? In this case, specifically, i'm curious about :force => true and what it's doing but the mor...

ruby one-liner for this possible?

Any chance the 2nd and 3rd lines can be combined in an one-liner and hopefully save one valuable? def self.date_format record = find_by_key('strftime') record ? record.value : "%Y-%b-%d' end the above function in a Config model try to fetch a database record by a key, return a default if not found in database. Even better if can...

How to execute multiple succeeding functions in 1 line in Ruby?

I have two succeeding function with the same condition and I wonder what is the best way to write this? I know the one way to do this is using if (condition) ... end, but I'm wondering if I can do it in one-line similar to bash, '[$n == $value] echo "$n" && break'. n = 0 loop do puts n if n == value # puts and break is having the same...

Confusion of integrating libs in Ruby on Rails

Hi, I am new to Ruby on Rails. I am using Netbeans IDE. While importing a new project, I used the inbuilt JRuby 1.4 that comes with Netbeans as the Ruby version. The main reason I want the JRuby is because of its debugging abilities. Now the doubt/problem I have is integrating libraries/plugins. One of the assignments I have requires ...

grouping comments by parent object, ordering parent object by oldest comment

I have objects that have comments. As part of a periodic email summary, I want to determine comments for a period, and present the objects in the order of oldest commented object first. Data: object_id comment_id 30 40 40 42 32 41 30 43 32 44 Output: Object #30 comment 40 comment 43 Objec...

How do I create a SOAP envelope in Ruby?

I am using Savon to build the client, but want to kno how to create the actual envelope. I am thinking of using Nokogiri XML Builder and just pass in the values, but not sure if that's the right way. The SOAP envelope specs can be found here: http://api.postalmethods.com/PostalWS.asmx?op=UploadFile ...

How can I get Capistrano to include .htaccess files in deployments?

I'm trying to get Capistrano deploying my web app. I'm deploying a php app using remote_cache from a git repo to a Linux host via a Windows computer. Everything is deploying okay except that it doesn't copy over the .htaccess files. I'm new to Capistrano and Ruby, so any pointers would be helpful! Capistrano 2.5.18 with Ruby 1.8.6 on...

Changing HTTP header in Rails

I am trying to communicate with a RESTful service in Rails. It can return data in different formats, json and xml. Is there a specific way that I can get the data type that I want. The service mentions that ACCEPT needs to be set in HTTP header. I am not sure how to do that in Ruby. Currently I'm doing this for get response = Net::HTT...