I have blog with only one author. Author encapsulates many different fields that will appear on every page. Do I Need an Author Model?
Where should I store my author (I use MongoDB) and how can I do that in the rails way?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Essentially, you want a model with only one row? The easiest way would probably be to do just that. In your seeds.rb file, just create a new author:
Author.create :name => "Dmitry", :rails_skill => 9001That way, you can always access it withAuthor.first, and just don’t ever write code to create a new author anywhere.That feels kind of odd though. If you’re building this for yourself and don’t care about the ability to add new authors in the future, you could either hardcode the author information everywhere it needs to be printed (gross) or build a custom initializer to set the author information and access it something like Sergio’s answer.