2

When scaffolding in Rails 3 the generator does this:

<% if @user.errors.any? %>
<div id="error_explanation">
  <h2><%= pluralize(@user.errors.count, "error") %> prohibited this user from being saved:</h2>

  <ul>
  <% @user.errors.full_messages.each do |msg| %>
    <li><%= msg %></li>
  <% end %>
  </ul>
</div>
<% end %>

But what about i18n? The messages get translated but why the hardcoded headline? Am I supposed to translate that manually? That doesn't seem very DRY?

Regards,

Jacob

jriff
  • 1,947
  • 3
  • 23
  • 33

2 Answers2

2

you can override scaffold default behavior by downloading the files here on github and place em in your lib/templates/erb/scaffold. When you generate scaffold it realize the templates are there and use those.

<% this code is executed and probably result in html %>, <%% this is converted to snippet %>, it was not that difficult and then you can perform all your personalizations, but to have the yml file automatically generated could be harder, anyway you can still get your templates almost done automatically.

To answer your question I do too think scaffold could be improved, but I read everywhere developers prefer to write their own code from scratch. Therefor I think, efforts are focused on improving other features. Scaffold remains at the very least a useful generator to understand and get familiar with the logic when you're a beginner.

ecoologic
  • 10,202
  • 3
  • 62
  • 66
  • Note -- it's `lib/templates/erb/scaffold` with a plural `templates` – Clay Sep 20 '11 at 17:16
  • scaffold is also useful to develop admin functionality – ecoologic Oct 21 '11 at 09:45
  • That's interesting -- I hadn't considered that. You just add the hooks to the templates that allow/prevent certain actions based on admin rights? – Clay Oct 21 '11 at 13:02
  • I mean that usually admin has control over the whole model and don't need an advanced interface, one line in the console, one css file, before_filter require_admin and job done. – ecoologic Oct 21 '11 at 14:03
0

I think that scaffolding is more a hint than a final template.

you may want to add translation simply substituing "prohibited this user from being saved:" with t('my_message') and dding 'my_message: whatever' to the en.yml. Adding a translation you have no repetitions and the dry principle is safe.

Just a comment aside: I seldomly use a message like "4 errors prohibited this user from being saved". In my experience is more common just to list all the errors occurred and to display the wrong field in a kind of red.

gicappa
  • 4,862
  • 1
  • 19
  • 23