ruby

Why does ruby's '$:' or '$LOAD_PATH' change when I run it with sudo?

I am trying to run a ruby script as root. When I try to require a gem, ruby says it can't be found. This is because of $: $ ruby -e "puts $:" /opt/local/lib/ruby/gems/1.9.1/gems/activesupport-3.0.0.beta4/lib /opt/local/lib/ruby/gems/1.9.1/gems/cgi_multipart_eof_fix-2.5.0/lib /opt/local/lib/ruby/gems/1.9.1/gems/daemons-1.1.0/lib /opt/loc...

Is anyone using the Ambitious adapter for ActiveRecord?

http://ambition.rubyforge.org/adapters/activerecord.html What are your experiences? ...

How to determine the number of accepted arguments in a lambda in ruby

Is there any method or something x in which, provided z = lambda {|x, y, z| nil} we can say z.x #=> 3 Of course, syntax can differ if it gets the job done. Thank you! ...

how to create a "nested split" of sorts

This seems like it should be fairly simple, but for some reason I can't think of the right way to do this: I have a string h that looks something like one(two(three four) five six) seven. I'd like to split this up into an array of hashes so that the output is something like {'one' => {'two' => {'three' => nil, '...

Trouble installing passenger gem on Ubuntu

From the console: adelevie@ubuntu:~$ gem install passenger Building native extensions. This could take a while... ERROR: Error installing passenger: ERROR: Failed to build gem native extension. /usr/bin/ruby1.8 extconf.rb /usr/lib/ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require': no such file ...

Why can't open4 read from stdout when the program is waiting for stdin?

I am using the open4 gem and having problems reading from the spawned processes stdout. I have a ruby program, test1.rb: print 'hi.' # 3 characters $stdin.read(1) # block And another ruby program in the same directory, test2.rb: require 'open4' pid, stdin, stdout, stderr = Open4.popen4 'ruby test1.rb' p stdout.read(2) # 2 characters...

Installing a gem from a repo I cloned on git hub

Post says it all. I've cloned a gem (particularly radiant) after clone it from its github source. Anybody tell me how I can install it as a gem? Something like "gem install radiant --local"? Thanks, Joe ...

Ruby logical operators

Possible Duplicate: Is there any wisdom behind and, or operators in Ruby ? What is the difference, if any, between the following pairs of logical operators? && vs. and || vs. or ...

trying to extend ruby with win32 programming

I have some C++ Win32 code that I want to call from Ruby. But the code needs to be set up like this int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd) otherwise things don't work right when I try creating windows and stuff. I don't know how to do that with a Ruby extension. What can I do? Is the...

Loading up first time server for Rails 3, and received this error..

Started GET "/users/new" for 127.0.0.1 at 2010-07-11 23:07:03 -0400 Processing by UsersController#new as HTML Completed in 15ms I18n::UnknownFileType (can not load translations from /Users/johnsmith/.rvm/gems/ruby-1.9.2-head/gems/activesupport-3.0.0.beta4/lib/active_support/locale/en.yml, the file type yml is not known): I check out...

Using acts_as_recommendable for a production site

Hi...I was looking for ways to include recommendations in my application. I came to know about acts_as_recommendable plugin. I would like to know your experiences while using it in your application. I would like to specifically know about Accuracy Pitfalls and any other stuff you would like to point out Thanks :) ...

How to convert a Ruby object to JSON?

Say I would like to do something like this, is it possible? require 'json' class Person attr_accessor :fname, :lname end p = Person.new p.fname = "Mike" p.lname = "Smith" p.to_json ...

Render a partial in a <div> on clicking a link tag

How can i render a partial inside a tag on the clicking of a href tag. <a href = "#" class= "addWidget" value = "Add Widget">add</a> <script type="text/javascript"> $(".addWidget").click(function(){ <%= render :partial => 'form'%> }); </script> ...

How can I DRY this code?

This is a Ruby code: if (@user.isAdmin?) @admin_profile = AdminProfile.new @user.admin_profile = @admin_profile @admin_profile.save @user.admin_profile_id = @admin_profile.id else @personal_profile = PersonalProfile.new @user.personal_profile = @personal_profile @personal_profile.sav...

How to parse the contents of a uploaded file in RoR

I am new to Rails. In my project where users have to upload a file, I store it then I have to parse the file contents and show it in new form. I have successfully done the file uploading portion, now how should I read the contents of it? ...

Ruby - internationalized domain names

I need to support internationalized domain names in an app I am writing. More specifically, I need to ACE encode domain names before I pass them on to an external API. The best way to do this seems to be by using libidn. However, I have problems installing it on my development machine (Windows 7, ruby 1.8.6), as it complains about not f...

Is Ruby on Windows failing when dealing with IPv6?

So I've got a tool that I built in Ruby that uses net/http to make some requests to an external REST service. I built and unit tested this tool using Windows 7 and it worked absolutely fine. Now, since this tool is meant to be run periodically on one of our servers (running Windows Server 2008 R2), I deployed it there and suddenly it's ...

Ruby parsing HTML for CSS files

Hi, I am working with some HTML for my site, I am basically moving my site from PHP to Rails. I have literally thousands of pages and some parts of the site have different CSS files from others. I can grab the tags fine but I added some conditions for different stylesheets to be loaded if its IE6/IE7/IE8 etc. I am trying to figure o...

ActiveRecord::StatementInvalid (Mysql::Error: PROCEDURE db_name.proc_spName can't return a result set in the given context: ....

I have use activerecord to access data from db. It works fine in localhost but when I tried it on another server, I get the following errors: ActiveRecord::StatementInvalid (Mysql::Error: PROCEDURE db_name.proc_spName can't return a result set in the given context: CALL proc_spName(............)): /vendor/rails/activerecord/lib/acti...

how to find the closing of an application window if not' log out' the session.

How to find the closing of an application window without ' log out' the session .This is to prevent the user from directly going to the previous session. In such cases, the user session should end and direct the user to the login page. ...