I am using Ruby on Rails and I would like to render a web page that makes use of database data for promotional purposes. The source code is stated something like the following:
# Model
PROMO_ID = 9
# Controller
@promo_article = Article.find(PROMO_ID)
# View
<%= @promo_article.title %>
<%= @promo_article.content %>
In the above code I "simply" look for an object instance (a promotional one) relating a database record and then I render it in the view. However, by using the above code, I have to ensure the record existence (that having the id
equal to that stated for PROMO_ID
) as a requisite, otherwise the application may raise errors.
I am in trouble because, in order to make the page to work, the record must be present in both development and production database and its reference PROMO_ID
may differ since in development it may be 9
(as in the above code) and in production it may be 378
.
I thought of using mock objects for my purposes but I would like to use a database record because this way the "promotional" record can be further processed by users. I am looking for a balanced and lean solution to the issue.
What do you advice about? How should I proceed? Should I state some id
constants or use mock objects?