Daniel N wrote:
Is this a nasty abuse of MVC?
In MVC, the model provides its data in neutral form and the view decides
how to present it. This is a clean separation of concerns (and
separation of concerns is one of the cornerstones of object orientation).
In your proposal, the model has to cater for a variety of ways of
returning each of its attributes (these would all have to be able to
vary independently) and the view has to know how to program the model to
give the attribute values in the form you want.
Thanx for the feedback. I’ve responded below.
Sorri if this is a double post. I got a message to say that it wasn’t delivered.
This would be via the include statement
<% Building.include PhoneNumberFormat %>
The model knows nothing of formatting until the very last
instant. Then immediately forgets at the end of the response
cycle. Since the view is last, this is effectively; immediately
Then what happens when you want a new format, that hadn’t been
anticipated by the model? You have to:
- add the new formatting capability to the model
Add a new format to the mixin module, not the model
- add the ability to switch to that format in the model
The view would control which module is mixed in at runtime. This
doesn’t need to be done in the model at all as far as I can tell.
- do that switching in the view.
Bear in mind that there’s practically no limit to the different ways in
which data may be presented (graphical as well as textual), and it
should be crystal clear that putting the knowledge of how to do this in
the model is a recipe for disaster.
Perhaps your right. I was thinking along the lines of a
form builder. I can (& I believe should) have a form defined
in a view something like
<% form_for :user, :builder => MyBuilder do |f| %>
<%= f.text_field :name %>
<%= f.text_field :email %>
<%= f.password_field :password %>
<%= f.password_field :password_confirmation %>
<% end %>
I can have the builder generate whatever I like. I can even select the builder programatically if I want.
I can have that form rendered as a table, or as divs, spans
whatever. All I need to do is build the builder the way I
want. Then all my forms across the site are consistant.
My thinking was along the lines of this. If you have a
DateFormatter module and you could tell it to format all dates of a
model a particular way.
Again the syntax is not correct at the moment but something like this inside a view or in the views helper.
<% MyModel.include DateFormatter do %>
<% date_fields :all, “%d %m %y” %>
<% end %>
I’m not sure how any of the issues that you raised are a problem.
Not saying they’re not… Just I don’t understand how they are yet.