Newbie: Models and Views and Controllers, oh my...

Hi!

I am very new to Ruby on Rails; I just started this week and I'm struggling to try to understand it.  I've read the LAMP tutorial along with Amy's, and started reading the Agile Web Developer book. 

I am having some problems though.  First off, I am very (still) confused about Models, Views, and Controllers.  From my understanding, views are what the end user sees.  Models do database stuff and Controllers is the space between Views and Models.  Basically, it tells the database to import data, check/validate data, etc.  Am I on the right path so far?

When creating a Rails app, you run 'ruby script/generate <something>'.  The something being either model, controller, or scaffold.  How do you know which one to run?  Is there one that just creates all three (model, view, and controller)? 

 I'm sure I'm going to have a bunch more questions later, but I just need a little kick to start going first.

Thanks!
Mike

The next step we recommend to everyone is to read the book “Agile Development with Ruby on Rails”. It will answer all of your questions.

models : represent data / control access to data (create read update delete) / validate data / contain all business logic

controllers: route user requests to models

views: the user screens.

A User model has methods that let me find all users in the system.

A User controller has a method that allows a user to request a list of users by calling this URL:

user/list

This controller invokes the method on the User model to retrieve the users into a variable.

A list view (located in views/user/list.rhtml) then contains the code that displays the results by using the variable set in the controller.

That’s pretty much all there is to models, views, and controllers… but read the book. It’s valuable to newcomers.

Definitely read the book. Twice. =)

if you create a table in a database, set up config/database.yml with
your DB info, and do
ruby script/generate scaffold [table name]
it will generate your model, controller and several views(for CRUD
functions)
the first time I tried that while learning rails and going through
AWDWR, it blew my mind. =)

Jason

Michael Wisniewski wrote:

What is AWDWR?

I picked up the Agile Development w/ Ruby Rails book and started going
through it. But, I have to agree with you, maybe I should read it
twice...or three times.

I feel like there's a LOT of power using Ruby on Rails and that is why
I really want to learn it. But at the same time, it's hard giving up
PHP because that's what I know.

Looks like I have some reading to do this weekend!!!

Thanks for your help,
Mike

Learn Ruby first.

Programming Ruby (commonly referred to as the Pickaxe book)
1st ed.: http://www.rubycentral.com/book/ or
http://www.ruby-doc.org/docs/ProgrammingRuby/
2nd ed.: http://pragmaticprogrammer.com/titles/ruby/index.html

Then learn Rails.

Agile Web Development with Rails (commonly referred to as AWDWR)
1st ed: check your favorite local or online book store
2nd ed: http://www.pragmaticprogrammer.com/title/rails/

You'll be a happier person.

Once you have the basics you can supplement your self-education with
blogs, wikis, forums, irc, etc. Oh and experiment.

Ah, this helps a little too. Thank you very much for taking the time
to write.

I read a lot of the "Pragmatic Programmers - Programming Ruby", second
edition. After getting through most of the book this weekend, and how
I started to read the "Agile Web Development with Rails" book last
week, I'm still a little confused....book-wise.

There's a book on how to learn ruby, which is great. But, like
learning any language, I find that they are all similar, it's just a
matter of learning the syntax.

Now, the problem. It seems like the first book (learning Ruby) is
good, but doesn't talk much about databases. Now the second book
(AWDwR) is good, but jumps into databases too quickly. Too bad there
isn't something in the middle....or is there?

Thanks!

Hi --

Alright, I started to look at yet, another book, and I think I found
the winner.

The "Ruby on Rails: Up and Running" book from Curt Hibbs and Bruce Tate
seems to be, at least for me, the bridge between "Pragmatic Programmers
- Programming Ruby" and AWDwR.

I haven't been through the whole book yet, but just going through some
of the example chapters, I thought was awesome. It explains how to get
your database configured and the relationships created. And best of
all, it all pretty much makes sense.

I think if I go through the book another time or two, it will make a
LOT more sense. If nobody has seen it, definiately pick it up. It
just came out and it's from O'Reilly.

Thanks!

Thanks for the compliment, I’m really glad you are finding the book helpful. If you feel so inclined, it’d be nice if you could post some review comments on Amazon:

http://www.amazon.com/o/ASIN/0596101325/ref=s9_asin_title_1/104-0132011-7007920

Curt