I am working a Bibtex database for my school using Rails and I need some
idea
on how to manage the bibtex types.
I crated an Author and Publications model and put
has_and_belongs_to_many
relationship between them.
The user model basically is like this:
class User < ActiveRecord::Base
has_and_belongs_to_many :publications
end
The Publication model has all the Bibtex fields and I use STI for
managing the
bibtex types like:
class Publication < ActiveRecord::Base
has_and_belongs_to_many :users
end
class Article < Publication
# An article from a journal or magazine. Required fields:
author,
title, journal, year.
# Optional fields: volume, number, pages, month, note.
validates_presence_of :title, :journal, :year
end
end
class Book < Publication
# A book with an explicit publisher. Required fields: author or
# editor, title, publisher, year.
# Optional fields: volume or number, series, address, edition,
month,
# note.
validates_presence_of :title, :publisher, :year
end
class Booklet < Publication
# A work that is printed and bound, but without a named
publisher or
sponsoring institution.
# Required field: title. Optional fields: author, howpublished,
address, month, year, note.
validates_presence_of :title
end
class InBook < Publication
# A part of a book, which may be a chapter (or section or
whatever)
and/or a range of pages.
# Required fields: author or editor, title, chapter and/or
pages,
publisher, year.
# Optional fields: volume or number, series, type, address,
edition,
month, note.
validates_presence_of :title, :chapter, :pages, :publisher,
:year
end
class InCollection < Publication
# A part of a book having its own title. Required fields:
author,
title, booktitle, publisher, year.
# Optional fields: editor, volume or number, series, type,
chapter,
pages, address, edition, month, note.
validates_presence_of :title, :booktitle, :publisher, :year
end
class InProceedings < Publication
# An article in a conference proceedings. Required fields:
author,
title, booktitle, year.
# Optional fields: editor, volume or number, series, pages,
address,
month, organization, publisher, note.
validates_presence_of :title, :booktitle, :year
end
Now this is ok but in the view part I want to create a form that would
display
certain fields based on the publication type. For example Article has
some
required, optional and ignored fields. I want the view (Create/Edit) to
show
only those attributes relevant to a publication class.
I tried overriding the content_columns but in console I get a stack too
deep
error or segfaults sometimes.
I tried this
class Article < Publication
validates_presence_of :title, :journal, :year
def self.content_columns
return Article.content_columns.delete_if {|c|
[“publisher”].include?(c.name) }
end
end
Any ideas on how to do this without having to create a different view
for each
publication type?
regards,
Horacio