John Merlino wrote in post #1104251:
> As you can see, my view helper makes use of the sort_column and
> sort_direction methods to check the current values in the params hash
> to determine how to render the links. So those methods have importance
> both in the controller and view layer. So it would make sense to
> define the methods once and reuse them in both layers. So what is
> wrong with this technique and how else could it be done so as not to
> violate the MVC structure and separation of concerns?
First a disclaimer... Everything I'm about to say is an opinion, nothing
more, nothing less.
As a developer who has worked with a number of MVC frameworks I really
don't consider Rails to be a very "pure" MVC. Views and controllers are
more tightly coupled to each other than in other MVC systems I've worked
with.
Take the simple example that controller instance variable are "made
available" in views. That's a lot of knowledge that the view has about
the controller, where in a "pure" MVC environment a view would know
nothing about the internal implementation of a controller.
For example, a text field in a desktop style application is a "pure"
view object. It has zero knowledge about the controller that interact
with it nor the model where the controller gets the data. That text
field can be used in any context, anywhere, in any application without
modification.
Compare that to something like:
form_for @product
This is obviously a view component (a form) yet is has direct knowledge
of what type of object it gets it's data from (an instance of a
Product). The product is provided to the view template by the controller
through a form of "injection," but having this direct dependency ties
the view to working with a specific type of model object that is
provided by a specific controller instance.
My point is not to start a war around the definition of MVC. I'm just
saying that MVC is a guideline pattern. If you have a solution that
works well for your application then feel free to use it.
--
Posted via http://www.ruby-forum.com/.
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
No comments:
Post a Comment