Forum: Ruby on Rails MVC "what to put where?"

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
E3513c4edd6810bb4b9914b58da2a2c3?d=identicon&s=25 Jamal Soueidan (jamal)
on 2007-02-16 18:53
Hello there,

I'm little confused about the MVC, I don't really know how to use it, as
I understand the controller are used for events, and the view is what
the visitor will see, and the model where you assign the variables which
view would use?

Is this correct?
If yes, then why do I validate things in Model (below)? isn't this a
event which should be in the controller?

  def validate
    errors.add(:username, "must not be john") if username == "john"
  end

I hope someone can give me a link or anything to understand where things
should be (MVC)?

Thanks for any little help :)

//Jamal
2f9a03aa0fcfe945229cb6126eda2cb2?d=identicon&s=25 Philip Hallstrom (Guest)
on 2007-02-16 19:22
(Received via mailing list)
>    errors.add(:username, "must not be john") if username == "john"
>  end
>
> I hope someone can give me a link or anything to understand where things
> should be (MVC)?

This is how I think of things...

Models - this is lower level business logic that is applied to well,
your
models. So if you want to enforce that your Person model has a middle
initial, this is the place to do it because to interact with Person's
you
*have* to go through the model to do it.  So, regardless of whether the
request is coming in from the website, an email, or script/console you
can
enforce rules here.

Controller - this is higher level and really only relevant as far as
your
website is concerned.  So this is where the logic goes to say display a
Person and setup any other variables you want to display in your view.

View - this is displayed to the end user and has the variables created
in
the controller available to it.
This topic is locked and can not be replied to.