Forum: Ruby on Rails Does passing the params collection to a model break mvc?

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
181976602397443ce119909b9d82cae2?d=identicon&s=25 blinking bear (Guest)
on 2008-12-05 16:10
(Received via mailing list)
I want to pass the params collection from the controller to the model to
parse filtering and sorting conditions.  Does having a method in the
that takes the params from the controller break MVC?
6fabb84e727dee98d1277df56458cbac?d=identicon&s=25 Andrew Bloom (Guest)
on 2008-12-07 22:02
(Received via mailing list)
Not necessarily. The params object is just a hash. There is no reason
why you can't or shouldnt pass a configuration hash to a method. I do
something similar quite often. One instance I find myself working with
is XML API's that I must generate. Many options are available on the
query string. To handle this I use a pattern similar to the example

@models = Model.collection_for_api(params[:model])
render :xml => @models

def self.collection_for_api(opts = {})
  # assemble a bunch of named scopes based on opts
9fd06f0bb22626a61d91ad8296e8f10d?d=identicon&s=25 Leonardo (Guest)
on 2008-12-08 00:22
(Received via mailing list)
You're passing unnecessary knowledge to your model.
It definitely doesn't need to know the controller and/or the action
it's being called from. And this information is by default in the
params hash of any given controller action.
Thus, it's considered a bad practice - bad design. Your objects should
assume as little as possible about any other structure on your

Leonardo Borges
6fabb84e727dee98d1277df56458cbac?d=identicon&s=25 Andrew Bloom (Guest)
on 2008-12-08 06:11
(Received via mailing list)
If you notice I only pass a section of the params has designed
specifically to build the appropriate query, not the entire hash.
This topic is locked and can not be replied to.