# A problem with a cgi

**URL:** <https://www.ruby-forum.com/t/a-problem-with-a-cgi/104286>\
**Category:** Ruby\
**Created:** [May 16, 2007, 11:45am UTC](https://www.ruby-forum.com/t/a-problem-with-a-cgi/104286 "2007-05-16T11:45:47Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![music](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/7c8e57/32.png) [@music](https://www.ruby-forum.com/u/music)\
**Post date:** [May 16, 2007, 11:45am UTC](https://www.ruby-forum.com/t/a-problem-with-a-cgi/104286/1 "2007-05-16T11:45:47Z")

</div>

Hello.  
I’m trying to know how to use cgi with ruby.  
I have write this file to connect to a ldap server and to insert data:

proxy1LDAP.rb

require ‘ldap’

class Proxy1LDAP

def initialize  
@base = “ou=People,dc=mydomain,dc=it”  
@admin = “cn=admin,dc=mydomain,dc=it”  
@passwd = “xxx”  
@conn = LDAP::Conn.new(“localhost”)  
@conn.set\_option(LDAP::LDAP\_OPT\_PROTOCOL\_VERSION, 3)  
@dominio = “@mydomain.it”  
end

def connetti  
@conn.bind(@admin, @passwd)  
end

def inserisci(account)  
newentry = {  
“objectClass” =\>  
[“top”,“person”,“organizationalPerson”,“inetOrgPerson”,“posixAccount”],  
“sn” =\> [account[“cognome”]],  
“cn” =\> [“#{account[“nome”]} #{account[“cognome”]}”],  
“mail” =\> [“#{account[“uid”]}#@dominio”],  
“homeDirectory” =\> [“/var/vmail/#{account[“uid”]}”],  
“uid” =\> [account[“uid”]],  
“userPassword” =\> [“{CRYPT}#{account[‘passwd’]}”],  
“employeeNumber” =\> [account[“codice”]]  
}  
@conn.add(“uid=#{account[‘uid’]},#@base”, newentry)  
end

def cerca

end

def elimina

end

end

and then I have this cgi:

#!/usr/bin/ruby

require ‘proxy1LDAP’  
require ‘cgi’

cgi = CGI.new  
account = cgi.params

puts “Content-type: text/plain”  
puts

#cgi.out(“text/plain”) {  
acc=Proxy1LDAP.new  
acc.connetti  
acc.inserisci(account)

When I run this cgi the web server error is:

/usr/lib/cgi-bin/ruby/accMail1.rb:4:in `initialize’: wrong argument type  
Array (expected String) (TypeError), referer:  
[http://localhost/prove/mail1LDAP.html](http://localhost/prove/mail1LDAP.html)

What’s the argumenti type error in the initialize method?  
If I run proxyLDAP.rb standalone I have no errors and all works well  
with ldap server.  
Why it doesn’t work if I use the cgi?

---

<div class="post-metadata">

**Author:** ![music](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/7c8e57/32.png) [@music](https://www.ruby-forum.com/u/music)\
**Post date:** [May 16, 2007, 6:22pm UTC](https://www.ruby-forum.com/t/a-problem-with-a-cgi/104286/2 "2007-05-16T18:22:52Z")

</div>

> puts  
> [http://localhost/prove/mail1LDAP.html](http://localhost/prove/mail1LDAP.html)
> 
> What’s the argumenti type error in the initialize method?  
> If I run proxyLDAP.rb standalone I have no errors and all  
> works well with ldap server.  
> Why it doesn’t work if I use the cgi?

CGI::params returns an array of the parameters posted to the cgi script.  
You’ll need to either (a) pass individual elements of the array  
concatenated into a string, or (b) handle an array in your initialize  
method.
