I have installed openLDAP and using net-ldap to work with that in Ruby on Rails. The thing here is i am able to bind and serach with this gem, but qhen it comes to add an entry to directory:
#auth = {:method => :simple, :username => "cn=admin,dc=example,dc=test", :password => "password"}
PORT = 389
HOST = "127.0.1.1"
NET::LDAP.open(:host => HOST, :port => PORT, :auth => #auth) do |ldap|
#ldap.add(:dn => dn, :attributes => attr) .
this error stop everyhing: uninitialized constant LdapsController::NET,[point to open line]
net-ldap is installed
ruby 2
rails 4
os: Ubuntu 13.4
Have you tried:
Net::LDAP
Case matter!
Related
I have written a rake task to update my database which I am doing by a model. I have called the function of model inside my rake task like this:
get_first_student = Student.get_first_id
I have written the model Student like following:
class Students < ActiveRecord::Base
attr_accessible :id, :roll_num :name, :class
self.table_name = 'students'
if Rails.env == "development"
CONN1 = establish_connection :adapter => "mysql2",
:database => "mydb_dev",
:username => "root",
:password => "" ,
:host => "localhost"
CONN2 = establish_connection :adapter => "mysql2",
:database => "mydb2_dev",
:username => "root",
:password => "",
:host => "1.2.3.4"
else
CONN1 = establish_connection :adapter => "mysql2",
:database => "mydb_prod",
:username => "root",
:password => "" ,
:host => "localhost"
CONN2 = establish_connection :adapter => "mysql2",
:database => "mydb2_prod",
:username => "root",
:password => "" ,
:host => "localhost"
end
def self.get_first_id
p "****"
p CONN1
p "****"
sql = %Q{SELECT MIN(id) FROM mydb.students;}
first_student_id = CONN1.connection.execute(sql).first[0]
return first_student_id
end
After running, I am getting this following output:
#<ActiveRecord::ConnectionAdapters::ConnectionPool:0x007f948c223120 #mon_owner=nil,
#mon_count=0, #mon_mutex=#<Mutex:0x007f948c2230d0>, #spec=#
<ActiveRecord::Base::ConnectionSpecification:0x007f948c2232d8 #config=
{:adapter=>"mysql2",:database=>"mydb_dev", :username=>"root", :password=>"",
:host=>"localhost"}, #adapter_method="mysql2_connection">, #reserved_connections={},
#queue=#<MonitorMixin::ConditionVariable:0x007f948c223080 #monitor=#
<ActiveRecord::ConnectionAdapters::ConnectionPool:0x007f948c223120 ...>, #cond=#
<ConditionVariable:0x007f948c223058 #waiters=[], #waiters_mutex=#
<Mutex:0x007f948c223008>>>, #timeout=5, #size=5, #connections=[],
#automatic_reconnect=false>
ActiveRecord::ConnectionNotEstablished
In rails, there are two different adapter for mysql server one in mysql and mysql2 gem. Check if you have mysql gem in your gemfile. If not, then open rails console, and type ActiveRecord::Base.establish_connection("mysql://your_username:yourpassword#localhost/yourdatabasename"). Have you configured your mysql server. Are you getting error in all environments?. Check it by login into mysql server using command 'mysql -u USERNAME -p' by default its root and with not password.
Calling establish_connection the second time has disconnected the first pool you created and that's the CONN1 you're trying to use.
Although this method returns a ConnectionPool object that you can capture and use, it's worth avoiding. ActiveRecord manages the connection pools and unless you explicitly tell it differently will assume you only want one of them active. Recently they've added some nice new ways to manage multiple databases.
I am using Redis with my ruby on rails application, To map Ruby object with Redis using redis-objects, dm-core and dm-redis-adapter. Below are the code snipts
Gemfile
gem 'redis-objects'
gem "dm-core", "~> 1.2.1"
gem "dm-redis-adapter"
/config/initializers/redis.rb
// LOCAL REDIS SERVER
Redis.current = Redis.new(:host => '127.0.0.1', :port => 6379)
// REMOTE REDIS SERVER
#Redis.current = Redis.new(:host => '<VM IP>', :port => <VM PORT>, :password => '<PASSWORD>')
Model.rb
DataMapper.setup(:default, {:adapter => "redis"})
class User
include Redis::Objects
include DataMapper::Resource
include ActiveModel::Validations
include ActiveModel::Conversion
# datamapper fields, just used for .create
property :id, Serial
property :name, String
property :email, String
property :des, Text
def id
1
end
end
User.finalize
It's working fine for local redis server. Why app always pointing local redis, Even when providing remote host and port?
SOLVED: checkout my answer.
As per Question:
// LOCAL REDIS SERVER
Redis.current = Redis.new(:host => '127.0.0.1', :port => 6379)
// REMOTE REDIS SERVER
#Redis.current = Redis.new(:host => '<VM IP>', :port => <VM PORT>, :password => '<PASSWORD>')
Model.rb
DataMapper.setup(:default, {:adapter => "redis"})
In above code, I am overloading Redis configuration in User model.
In that case, I need to write remote configuration in model as well.
DataMapper.setup(:default, {:adapter => "redis", :host => '<VM IP>', :port => <VM PORT>, :password => '<PASSWORD>'})
Redis.current is a method which always gives a new connection if the instance variable #current is empty. See https://github.com/redis/redis-rb/blob/master/lib/redis.rb#L19
def self.current
#current ||= Redis.new
end
Try assigning Redis.new to some other global like $redis. This should mostly fix your issue.
Issue: Net::HTTP calls failing when using jruby with a OpenSSL::SSLError Socket Closed, but working fine using MRI.
Side Note: Calls to many servers work, however this app is calling to a cisco sensor. Again, it works via MRI but not Jruby. I've tried a number of different things to no avail. I've tried jruby 1.6.7, 1.7, and the recently released 1.7.1.dev. I've also tried jruby-openssl-0.7.4, 0.7.7, and 0.8.0.pre3. I've even tried running the script with from Ruby 1.8, and 1.9.
Failing At https://github.com/jruby/jruby/blob/master/src/org/jruby/ext/openssl/SSLSocket.java#L404 ?
Similar Issue in research: http://jira.codehaus.org/browse/JRUBY-6346
Small Back Trace Excerpt
org/jruby/ext/openssl/Utils.java:79:in newError'
org/jruby/ext/openssl/SSL.java:92:innewSSLError'
org/jruby/ext/openssl/SSLSocket.java:192:in connectCommon'
org/jruby/ext/openssl/SSLSocket.java:162:inconnect'
org/jruby/runtime/callsite/CachingCallSite.java:306:in cacheAndCall'
org/jruby/runtime/callsite/CachingCallSite.java:136:incall'
org/jruby/ast/CallNoArgNode.java:64:in interpret'
org/jruby/ast/NewlineNode.java:105:ininterpret'
I have scoured google with no luck. Any help would be greatly appreciated.
It should also be noted that I am running OSX Mountain Lion 10.8.2.
[UPDATE]
I have ran out of time to debug this and used the following workaround:
Gemfile
gem 'typhoeus'
Test method
def send_post(url, body)
response = Typhoeus::Request.post(url,
:method => :post,
:disable_ssl_host_verification => true,
:disable_ssl_peer_verification => true,
:username => #auth[:username],
:password => #auth[:password],
:headers => {
'Accept' => 'text/xml',
'Content-type' => 'application/binary',
'Connection' => 'keepalive',
'Accept-Charset' => 'iso-8859-1,*,utf-8',
'Pragma' => 'no-cache',
'Cache-Control' => 'no-cache',
},
:body => body
)
response
end
When using MassiveRecord over thrift to save a record into HBase, I get a strange "abort" error.
Here is some code that will reproduce the error on Mac OS X, with hbase (0.92.0 and 0.94.0) install via homebrew.
require 'massive_record'
MassiveRecord::ORM::Base.connection_configuration = { :host => 'hbase' }
class Woot < MassiveRecord::ORM::Table
default_scope select(:data)
column_family :data do
field :name, :string
end
end
woot = Woot.new( :name => 'rawr' )
woot.save
This always causes the process to halt, leaving the message
[1] 8756 abort ruby massive_woot.rb
Retrieving works just fine, but I can't seem to save the records.
Here is what the schema looks like:
>> describe 'woots'
DESCRIPTION ENABLED
{NAME => 'woots', FAMILIES => [{NAME => 'data', BLOOMFILTER => 'NONE', REPLICATION_SCOPE => '0', VERSIONS => '3', C true
OMPRESSION => 'NONE', MIN_VERSIONS => '0', TTL => '2147483647', BLOCKSIZE => '65536', IN_MEMORY => 'false', BLOCKCA
CHE => 'true'}]}
1 row(s) in 0.0190 seconds
This turned out to be a versioning issue. MassiveRecord v0.2.2 depends on thrift 0.6.0 (specified by an "= 0.6.0" version in the Gemfile).
I solved this for now by pulling off the "develop" branch of MassiveRecord from github.
I'm trying to switch the session store in Rails 3 by changing the
config/application.rb as following:
config/application.rb
#-----------------------------------
memcache_options = {
:compression => true,
:debug => false,
:namespace => "xx-cache",
:readonly => false,
:urlencode => false
}
CACHE = MemCache.new(memcache_options)
CACHE.servers = ['127.0.0.1:17898']
#check if CACHE is connected
#puts CACHE
config.action_dispatch.session = {
:session_key => '_xx_session',
:secret => 'xx',
:cache => CACHE,
:expires => 900
}
config.action_dispatch.session_store = :mem_cache_store
#-----------------------------------
Memcache server is running. However, when run rails s, i got this
message:
=> Booting WEBrick
=> Rails 3.0.0.beta3 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
Exiting
/usr/lib/ruby/gems/1.9.1/gems/actionpack-3.0.0.beta3/lib/
action_dispatch/middleware/session/mem_cache_store.rb:19:in
`initialize': #<ActionDispatch::Session::MemCacheStore:0xa302950>
unable to find server during initialization. (RuntimeError)
It seems the session options was not passed correctly. But i'm not
sure what's wrong here cause I'm new to Rails.
Any help will be appreciated.
Thanks
I'm not -entirely- sure, but I think you need to include "cached_model." Try adding
require 'cached_model' #(At the top)
Let me know if that worked.