I am using Ruby and JRuby on a Ubuntu machine through RVM.
OpenLDAP is connecting and doing the CRUD operation through Ruby code with the Net::LDAP gem perfectly.
Here is the code:
require 'rubygems'
require 'net/ldap'
ldap = Net::LDAP.new :host => 'locahost',
:port => 389,
:async => 1,
:keepalive => 1,
:auth => {
:method => :simple,
:username => "cn=admin,dc=test,dc=com",
:password => "secret"
}
puts ldap.bind
When I execute the same code with JRuby, it throws an error:
$ jruby ldap_test.rb
ArgumentError: unsupported protocol family `__UNKNOWN_CONSTANT__'
initialize at org/jruby/ext/socket/RubySocket.java:188
new at org/jruby/RubyIO.java:847
Related
I can't seem to get email for password recovery using devise to work on my openshift app. I'm using Rails 4.0.2 and Ruby 1.9.3. I've tried the following in production.rb :
config.action_mailer.default_url_options = { :host => 'mydomain.com' }
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:port => 25,
:address => 'smtp.mailgun.org',
:user_name => 'postmaster#domain.com',
:password => '[password]',
:domain => 'mydomain.com.mailgun.domain',
:authentication => :plain,
}
I've also done settings required for google use and both worked fine in development on local. Also tried ports 465, 587, as described here. Sending mail unfortunately still isn't performed on production. The app just throws an error with nothing in the logs.
I'm trying to send emails via sendmail in Padrino. I did the configuration specified here (Configuration and Quick Usage)
But I always get the following error in the server log (on Heroku or localhost):
app[web.1]: sh: Illegal option -
app[web.1]: Errno::EPIPE - Broken pipe:
I installed the mail gem and I'm using Padrino 0.10.7
I'm using this, to send the email:
post :create do
email(:from => "tony#reyes.com", :to => "john#smith.com", :subject => "Welcome!", :body=>"Body")
end
That's practically all I have...
You should be using one of the parter addons for sending mail with Heroku.
A good option is Sendgrid
heroku addons:add sendgrid:starter --app=your_app_name
Then in your Padrino app in app.rb inside your App class:
set :delivery_method, :smtp => {
:address => "smtp.sendgrid.net",
:port => 587,
:domain => 'heroku.com',
:user_name => ENV['SENDGRID_USERNAME'],
:password => ENV['SENDGRID_PASSWORD'],
:authentication => :plain,
:enable_starttls_auto => true
}
You could substitute these for settings for another external SMTP server, or look at Mandrill for transactional emails.
I suspect the Errno::EPIPE error you were seeing was that it could not connect to a valid SMTP server, so your controller code should be fine as it is.
Pat is right, you don't need an add-on, just configure your app.rb like stef suggests and you're good to go. So, for example, we use gmail and our config looks something like this:
set :delivery_method, :smtp => {
:address => "smtp.domain.com",
:port => 587,
:domain => 'rails.domain.com',
:user_name => "rails#domain.com",
:password => "super-secret",
:authentication => "plain",
:enable_starttls_auto => true,
:openssl_verify_mode => OpenSSL::SSL::VERIFY_NONE
}
I m trying to use Datamapper as ORM for my Ruby/Padrino application. To setup db connection, in databse.rb, I have:
when :development then DataMapper.setup(:default, "mysql://db_user:dsfsdfs#localhost/my_app_development")
This work fine. But my requirement is to have complex password, something like:
when :development then DataMapper.setup(:default, "mysql://db_user:Passw0rd#13#localhost/my_app_development")
This doesn't work and I get error:
ruby/1.9.1/gems/addressable-2.2.8/lib/addressable/uri.rb:1179:in `port=': Invalid port number: "Passw0rd" (Addressable::URI::InvalidURIError)
I figured out that the '#' character is problem. Then I attempted doing this:
DataMapper.setup(:default,
{
:adapter => "mysql",
:database => "my_app_development",
:username => "db_user",
:password => "Passw0rd#13",
:host => "localhost"
})
When I do this, it seems like DM is ignoring the hash altogether; when I run
padrino rake db:create
It tries to connect as current logged in user, rather than the username specified here. Solution?
I suppose you still need to have to declare it like following, in case you are not
when :development then
DataMapper.setup(:default,
{
:adapter => "mysql",
:database => "my_app_development",
:username => "db_user",
:password => "Passw0rd#13",
:host => "localhost"
})
when :production then
# rest of your code
end
Got it - the key :username should be :user. Basically, the hash should contains keys as understood by Addressable::URI
require 'rubygems'
require 'jdbc/jtds'
require 'activerecord-jdbc-adapter'
config = {
:username => 'me',
:password => 'mypass',
:adapter => 'jdbc',
:driver => 'net.sourceforge.jtds.jdbc.Driver',
:url => 'jdbc:jtds:sybase://myserver:1234/mydb'
}
ActiveRecord::Base.establish_connection( config )
ActiveRecord::Base.connection.class
# => ActiveRecord::ConnectionAdapters::MssqlJdbcConnection
I realise that MSSQL and Sybase have a shared history, but is it correct that I get this adapter when connecting to Sybase?
My problem is that types are not being mapped to ruby type correctly. e.g. floats and, decimals are being translated to String.
Gems:
activerecord-jdbc-adapter 1.1.3
jdbc-jtds 1.2.5
ActiveRecord will resolved the JDBC adapter by adding the
:dialect => 'sybase'
...config option
I am using rails 3.0.3, ruby 1.9.2-p180, mail (2.2.13). I m trying to setup a mail interceptor but I am getting the following error
/home/abhimanyu/Aptana_Studio_3_Workspace/delivery_health_dashboard_03/config/initializers/mailer_config.rb:16:in `<top (required)>': uninitialized constant DevelopmentMailInterceptor (NameError)
How do i fix it?
The code I am using is shown below:
config/initializer/mailer_config.rb
ActionMailer::Base.default_charset = "utf-8"
ActionMailer::Base.default_content_type = "text/html"
ActionMailer::Base.raise_delivery_errors = true
ActionMailer::Base.perform_deliveries = true
ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.smtp_settings = {
:enable_starttls_auto => true,
:address => "secure.emailsrvr.com",
:port => '25',
:domain => "domain",
:user_name => "user_name",
:password => "password",
:authentication => :plain
}
ActionMailer::Base.register_interceptor(DevelopmentMailInterceptor) if Rails.env.development?
lib/development_mail_interceptor.rb
class DevelopmentMailInterceptor
def self.delivering_email(message)
message.to = "email"
end
end
Thanks in advance.
require 'development_mail_interceptor' #add this line
ActionMailer::Base.register_interceptor(DevelopmentMailInterceptor) if Rails.env.development?
I found it easier to install the mailcatcher gem. Then in development.rb:
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:address => "`localhost`",
:port => 1025
}
Then just run "mailcatcher" and hit http://localhost:1080/ in a browser. It runs in the background, but can be quit directly from the browser. Gives you text+html views, source, and analysis with fractal, if you swing that way. Super-clean.