-
Notifications
You must be signed in to change notification settings - Fork 2
example for unstable
This example is generated for the unstable-branch of 2008 05 22, which is the current stable branch.
The example creates a book storage system where books can have tags. For virtual historical reasons two fields of tags have to be added and they link to a separate table where the tags are defined (which is the only way for now, but that will probably change somewhere during the summer).
I’m a bit lazy, I’m just going to paste the code I used right here… it should suffice to redo it.
madnificent@Freyr ~/code/rails $ rails super_books
madnificent@Freyr ~/code/rails $ cd super_books/
madnificent@Freyr ~/code/rails/super_books $ cd vendor/plugins/
madnificent@Freyr ~/code/rails/super_books/vendor/plugins $ git clone git://github.com/madnificent/acts_as_taggable-done-right.git
madnificent@Freyr ~/code/rails/super_books/vendor/plugins $ cd acts_as_taggable-done-right/
madnificent@Freyr ~/code/rails/super_books/vendor/plugins/acts_as_taggable-done-right $ git checkout -b unstable
madnificent@Freyr ~/code/rails/super_books/vendor/plugins/acts_as_taggable-done-right $ git pull origin unstable
madnificent@Freyr ~/code/rails/super_books/vendor/plugins/acts_as_taggable-done-right $ cd ../../../
madnificent@Freyr ~/code/rails/super_books $ script/generate scaffold Book title:string tag_names:string super_tag_names:string
madnificent@Freyr ~/code/rails/super_books $ ruby vendor/plugins/acts_as_taggable-done-right/install.rb
# This created the Tags migration, it doesn't need a model (the ones generated through script/generate will create a model)
madnificent@Freyr ~/code/rails/super_books $ script/generate tag_support book
madnificent@Freyr ~/code/rails/super_books $ script/generate tag_table SuperTag
madnificent@Freyr ~/code/rails/super_books $ script/generate tag_support book SuperTag
madnificent@Freyr ~/code/rails/super_books $ mysql -u root -p
mysql> CREATE SCHEMA super_books_development;
mysql> grant all on super_books_development.* to 'bookdev'@'localhost' identified by 'password';
mysql> exit
I changed db/migrate/001_create_books.rb to contain ( this way we don’t have to change the views _ )
class CreateBooks < ActiveRecord::Migration def self.up create_table :books do |t| t.string :title t.timestamps end end def self.down drop_table :books end
end
I’ve set-up database.yml according to the user I created in the database:
development: adapter: mysql database: super_books_development username: bookdev password: password host: localhost encoding: utf8
I changed the code in app/models/book.rb to contain:
class Book < ActiveRecord::Base acts_as_taggable( { :tag_names_name => "super_tag_names", :tag_class => SuperTag } ) acts_as_taggable end
The second line is the tag-system with the SuperTag class which we generated manually. The third line is the standard system to add tags… It only uses standards.
There you go, migrate and run the application!