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
Related
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
I recently made a small wrapper in Sinatra. I had it working locally using SQLite, and I decided to switch to Postgres for the eventual move to Heroku.
However, I can't get my app to connect to my local postgres db. I'm running Windows 7 64-bit.
Here is database.yml:
development:
host: localhost
adapter: postgresql
database: postgres
username:
password:
Here is environments.rb:
configure :production, :development do
db = URI.parse(ENV['DATABASE_URL'] || 'postgres://localhost/postgres')
ActiveRecord::Base.establish_connection(
:adapter => db.scheme == 'postgres' ? 'postgresql' : db.scheme,
:host => db.host,
:username => db.user,
:password => db.password,
:database => db.path[1..-1],
:encoding => 'utf8'
)
end
This is the result when I try to rake:
Could not load 'active_record/connection_adapters/postgresql_adapter'. Make sure that the adapter in config/database.yml is valid. If you use an adapter other than 'mysql', 'mysql2', 'postgresql' or 'sqlite3' add the necessary adapter gem to the Gemfile.
I can connect to the db via psql and localhost just fine.
I am reading documents regarding NET::LDAP with TLS. But I could not find any mentioning regarding enforcing certificate validation with start_tls. The sample code is attached below.
ldap = Net::LDAP.new :host => params["host"],
:base => params["base_dn"],
:encryption => :start_tls,
:port => params["port"],
:auth => { :username => params["bind_dn"],
:password => params["bind_pw"],
:method => :simple
}
The document here "http://net-ldap.rubyforge.org/Net/LDAP.html#method-i-encryption" mentions there is no SSL certificate validation for simple_tls. But there is no information regarding start_tls.
no, I checked the latest 0.6.1 version, this functionality is still missing.
simple_tls is actually LDAPS which usually on port 636.
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
I'm trying to use ActionMailer without Rails in a project, and I want to use Haml for the HTML email templates. Anyone have any luck getting this configured and initialized so that the templates will be found and rendered? I'm currently getting errors like:
ActionView::MissingTemplate: Missing template new_reg/daily_stats/full with {:handlers=>[:erb, :rjs, :builder, :rhtml, :rxml], :formats=>[:html], :locale=>[:en]} in view paths "/home/petersen/new_reg/lib/new_reg/mailers/views"
To clarify, this is ActionMailer 3.0.4
Looks like the issue is that without the full Rails stack, Haml doesn't completely load, specifically the Haml::Plugin class. Adding require 'haml/template/plugin' after the normal require 'haml' line seems to solve the problems.
require 'haml/template/plugin' in the "configure do" block together with ActionMailer::Base.view_paths = "./views/" did it for me (Sinatra)
Not necessary in Rails -- but since you're using ActionMailer without Rails -- did you specify ActionMailer::Base.register_template_extension('haml')?
I'm seeing a similar issue and am using ActionMailer 3.0.3. register_template_extension does not exist in ActionMailer 3.
I'm using Sinatra. I've got mailer.rb (below) in APP_ROOT/lib and the views are located in APP_ROOT/views/mailer. This sends an email with a subject, the body is blank though.
require 'action_mailer'
ActionMailer::Base.raise_delivery_errors = true
ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.view_paths = File.dirname(__FILE__)+"/../views/"
ActionMailer::Base.smtp_settings = {
:address => "smtp.gmail.com",
:port => 587,
:domain => 'exmaple.com',
:user_name => 'user#exmaple.com',
:password => 'password',
:authentication => 'plain',
:enable_starttls_auto => true }
class Mailer < ActionMailer::Base
def new_comment_notifier(post,comment)
#post = post
#comment = comment
mail(:to => "user#example.com",
:subject => "new comment on: #{post.title}")
end
end