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
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, > HoracioYou 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 -- Posted via http://www.ruby-forum.com/.
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
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 ????????:> 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 > > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails
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 On 1/23/06, Horacio Sanson <hsanson@moegi.waseda.jp> wrote:> > > 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 ????????: > > 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 > > > > > > _______________________________________________ > > Rails mailing list > > Rails@lists.rubyonrails.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060213/5fee5781/attachment-0001.html
Hi Horacio, I joined the rails mailinglist only two days ago, but I''m looking for quite some time for a good Bibtex Webfrontend for our group. The main features should include the ability to search inside the Bibtex Database, and the ability to group them with some keywords. It would also be nice to add new articles in a webfrontend and to export specific articles as a single Bibtex file. So, if you already have something, that does this stuff (or part of it), I would really like to take a look at it! Bye, Michael -- Michael Schilling eMail : ruby@untiefe.de URL : http://glcu.sf.net/ "Change my name I remain the same." - Moloko