Install Rails 4.x :
gem install railsGenerate a new Firebird Rails application
rails new firebird_appdelete the generated database.yml sqlite config and use the one from bellow
Be aware about indentation
cat config/database.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Firebird 2.x database | |
development: | |
adapter: fb | |
database: /var/lib/firebird/2.5/data/rubyonfire.fdb | |
username: sysdba | |
password: masterkey | |
host: localhost | |
create: true | |
# Warning: The database defined as "test" will be erased and | |
# re-generated from your development database when you run "rake". | |
# Do not set this db to the same as development or production. | |
test: | |
adapter: fb | |
database: /var/lib/firebird/2.5/data/rubyonfire_test.fdb | |
username: sysdba | |
password: masterkey | |
host: localhost | |
create: true | |
production: | |
adapter: fb | |
database: /var/lib/firebird/2.5/data/rubyonfire_production.fdb | |
username: sysdba | |
password: masterkey | |
host: localhost | |
create: true |
gem 'activerecord-fb-adapter'Then run:
bundle update
rails generate scaffold Client name:string address:string email:string remark:text
rake db:migrateI have re-read the ruby guide
so i did these commands while following the official guide
rake db:createbut database was already created in flamerobin
script/generate controller home index vi app/views/home/index.html.erband write something there, start the server with
rails sand now you can see something in browser
http://localhost:3000/
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj_PN5G4yeRbw10lrF6IdU-dEAw0aoW3KM5NdPDTEys8OWxzzp0XnvbZ8fSftRaFdwmUHS7IoV-GfrD_D6-mtWNtJEvExiaxnMwfPzuu7HvVGUIhd-ON7Iw0KhwifDzwoNqzgmL/s200/first_rails_app_finished.png)
I have created the table and one sequence in firebird db
CREATE TABLE posts ( id BIGINT NOT NULL PRIMARY KEY, name VARCHAR(255), title VARCHAR(255), content VARCHAR(255), timestamps timestamp ); CREATE sequence POSTS_SEQ;
I have ran the scaffold again to generate the posts model/view/controller
script/generate scaffold Post name:string title:string content:textand then
started the server
rails s
Of course I have modified the route and added an link as in tutorial and now i can add and modify blog posts
note: in new rails route is defined this way in config/routes.rb
map.root :controller => "home"
http://localhost:3000/posts
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgTfLJp-i2lsmpbkgKuipmEoLHhqvRqgfHLqAz-JGa2WIuTRY7aILWvGSjFKy_FjRbaxX1ieNg1Shg_-HOqQWnfwjzf73uDbwVIZOY8QwOtc-2-fgK6LtaG2Gt785kMZ61DVRPI/s200/post_finished.png)
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh8eTK9qcLt9KBs0iqqYG3A4V0hOfgSRsdTjxtm1tyyHhbdIRau0C4q8sFtBMKa28N4pztuNmIv2-DYt9-dDCKdmXmq9JT5NNs0qpDEkh2APd7AjujH4j3GwWwVACd3mNZaFklW/s200/Listing_posts.png)
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEilaue37RtD8r_yFwiVgSW56FAV1idZrb4KQ4CHH-9dNukxH05sCQkMB4FWOUYSfVIisYpeExngxcZ5d6ba-YjlYvIha51Q0fSVP2m52tKl8AR89s3PKAq0wUjH9XB5esSDqqP2/s200/new_post.png)
Follow the normal ActiveRecord conventions for table names, primary key columns, etc. The one “extra” you’ll need for Firebird is that you’ll have to create a generator for any tables that require a sequence-based primary key. The default naming convention is TABLENAME_SEQ. So if you have a users table, you would need to create a corresponding USERS_SEQ generator
You don't need to create before insert triggers ! rails reads the value from sequence and then increments it in ruby code, Yay!
6 comments:
Hi Mariuz!
Great post! It's exactly what I needed.
I followed your tips, but I still got some issues.
I am using Firebird 2.5 and Rails 2.3.8. I've installed the to gems fb and fb_adapter and connected to the database successfully. But, when I tried to get an object from the database I've got the follow error:
>> p = Tbprod.first
ActiveRecord::StatementInvalid: Fb::Error: Invalid token
Dynamic SQL Error
SQL error code = -104
Token unknown - line 1, column 15
"TBPROD"
: SELECT * FROM "TBPROD" ROWS 1,
from /Library/Ruby/Gems/1.8/gems/activerecord-2.3.8/lib/active_record/connection_adapters/abstract_adapter.rb:221:in `log'
from /Library/Ruby/Gems/1.8/gems/fb_adapter-0.6.0/lib/active_record/connection_adapters/fb_adapter.rb:307:in `log'
from /Library/Ruby/Gems/1.8/gems/fb_adapter-0.6.0/lib/active_record/connection_adapters/fb_adapter.rb:312:in `select_all'
from /Library/Ruby/Gems/1.8/gems/fb_adapter-0.6.0/lib/active_record/connection_adapters/fb_adapter.rb:299:in `translate'
from /Library/Ruby/Gems/1.8/gems/fb_adapter-0.6.0/lib/active_record/connection_adapters/fb_adapter.rb:311:in `select_all'
from /Library/Ruby/Gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:664:in `find_by_sql'
from /Library/Ruby/Gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:1578:in `find_every'
from /Library/Ruby/Gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:1535:in `find_initial'
from /Library/Ruby/Gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:616:in `find'
from /Library/Ruby/Gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:626:in `first'
from (irb):2
Could you help me with that?
Please install fb_adapter from git
Seems that you have a version of adapter that you doesn't give the first row (ROWS feature was implemented later )
I have tested with version from git and first works
p = Post.new(:content => "A new post")
=> #
>> p.save
=> true
>> f = Post.first
=> #
The output was cleaned but here is on gist
https://gist.github.com/9dbec72ab99a70dcb9fa
I also requested a new version of the gem version
The message is about TBPROD
check if it works with select * from TBPROD
My guess is that is something wrong with the model/table
I never use dialect 1 but
rowland found the issue
I suspect a dialect 1 database and mixed-case table names are behind the errors. A backup/restore may solve Nielson's issue.
Actually, it turns out it is gfix which is required: http://www.firebirdsql.org/manual/gfix-dialect.html
Thank you!
It is working fine now =)
I changed the dialect to 3.
Post a Comment