Forum: Ruby on Rails Bibtex database design

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
81cf8dab4b4af8aa3148c28421afd845?d=identicon&s=25 Horacio Sanson (Guest)
on 2006-01-23 08:11
(Received via mailing list)
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
C8a634a01a2c4508360874bff7fb1a7f?d=identicon&s=25 Kevin Olbrich (olbrich)
on 2006-01-23 14:22
Horacio Sanson wrote:

>
> 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

You can do some if...then (or case..when) conditionals in the view which
depends on the publication type.

you can probably put in things like...

<%= text_field('name','id') if @object.isa? Book -%>

_Kevin
3f2ae5bbf68f4b4d546b23b6b4087b54?d=identicon&s=25 Bruce D'Arcus (Guest)
on 2006-01-23 16:35
(Received via mailing list)
Horacio Sanson <hsanson@...> writes:

> 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.

Since I think about this issue a lot, I'd like to prompt you to consider
whether you really want to base this on BibTeX, which has a poor
data model.

So rather than Author, how about Agent, and then have two
subclasses: Person and Organization.

You then relate those agents to Reference objects (which can be more
than just publications) through a HABTM join.

The reason is that I might be an author of one work, an editor of
another, and a translator of still another. Likewise, there are
organizational authors, and organizations also have other roles
(like publishers).

Other important classes and subclasses:

Event
Conference < Event
Hearing < Event
Publisher < Organization
Collection
Series < Collection
Periodical < Collection

So you can then think about relations like:

[Reference with type of "paper"]
authored by --> [Person "Jane Doe"]
presented at --> [Conference "ABC Conference"]
published in --> [Proceeedings "Proceedings of ABC Conference"]
published by --> [Publisher "XYZ Publishing"]

I tend to think that parts (article, chapters, etc.) might well be
stored in
the same table, but am not sure. I think reference types probably ought
to just be stored in a separate table for flexibility's sake.

Just a thought ...

Bruce
81cf8dab4b4af8aa3148c28421afd845?d=identicon&s=25 Horacio Sanson (Guest)
on 2006-01-24 04:43
(Received via mailing list)
Thanks,  I would really like to use a model different from the Bibtex
one.
Unfortunately the database is a legacy one in Bibtex format and has all
publications of my school since 1977 (quite a lot).

Changing the model may be a real challenge (Migrations maybe?). Anyway I
like
this idea of Events, Agents and Organizations...  I will look into it.

For now I will simply create a single View that displays the fields
depending
on the Class (subclass).


Horacio

Tuesday 24 January 2006 00:17ã?Bruce D'Arcus ã?ã??はæ?¸ãã¾ã?ã?:
4f86dba83a7b1b127263bb3fdd0b09e7?d=identicon&s=25 Ammon Christiansen (ammonc)
on 2006-02-13 20:50
(Received via mailing list)
maybe you could use yaml to store it all in one coumn.
One filld could be the type - inproceedings/artcle/... and the rest of
the
fields would just be in the yaml.  then you could construct the right
kind
of object
This topic is locked and can not be replied to.