How to Generate Controllers from the command line


#1

Am I doing this correct.

ruby script/generate controller Site index about help

after I run the line above from the command prompt it spits out

exists app/controllers/
exist app/helpers/
create app/views/site
Etc…

What does exists and create mean, is exists telling me that those
controllers now exists, and is create telling me I need to create
controllers? How do I create controllers for views and so forth?

I’m building my first app from a book called RailsSpace

Thanks


#2

Simply put, those messages are the generator telling you what it
found…

The app/controllers folder already exists.
The app/helpers folder already exists.
The app/views/site folder did not exist, and was created

Your controller is the glue between the model and the views for that
model…

Start a new rails project, and

ruby script/generate scaffold song artist:string duration:integer
genre:string

and see what gets created (all sorts of wonderful things). Peruse the
folder hierarchy and see what the parts are, and where they get created

  • songs controller, song model, song views, it’s all there, albeit in a
    very basic format.

Many folks disparage using scaffold, but it’s a great learning tool for
seeing a fully build out example.


#3

On 19 Feb 2009, at 17:26, Zayd C. wrote:

Etc…

What does exists and create mean, is exists telling me that those
controllers now exists, and is create telling me I need to create
controllers? How do I create controllers for views and so forth?

it’s saying that the app/controllers folder already existed but that
it had to create the app/views/site folder

Fred


#4

Being a newbie myself, I will add a word of caution.

Compare the version the book is based on, with what you are running. I
was on Rails 2.2.2 and its syntax for scaffold generation is different
from the earlier versions in the sense that the attributes are
expected in the command line now.

I learnt that the hard way.
So if you are using the latest and greatest, read the book with a
pinch of salt and check the net when in doubt!

Hope this helps.
I am using Rails 2.2.2 on Ruby 1.8.6 using MySQL 5.0 on WinXP. This
config just works for me.

Aside: Started off with Komodo and then jRuby on NetBeans IDE , using
MySQL 6.0 on Vista 64-bit but it was a mess cause half the time the
IDE was tripping me up and some gems/plugins wouldnt install
correctly. Dont know if it was because of Vista or NetBeans on 64-bit.
I had to use MySQL 6.0 as that is the only one which would run on
Vista 64-bit. but then some Rails stuff was not certified for mySQL
6.0 so ultimately I got out of that rat hole.

cheers
On Feb 19, 9:47 am, Frederick C. removed_email_address@domain.invalid


#5

Hey, welcome to the club!

I am in same boat. and m learning as I go. If you know Ruby basics,
you can dive into Rails tutorials. and working on a real program then
whets your appetite.

As for myself - I am reading The Rails Way by Obie after looking at a
few other books. It gives me context around the rails constructs.
I read a book about Ruby too as that was a huge stumbling block for
me. The syntax is different as I come from C,C++, Java world. This
book I skimmed thru as I just needed to get familiar with the
different syntax.

The rest will come as I work thru code and look at other code. That
said, everyone has their own best way of learning!

cheers from another newbie!

On Feb 19, 4:08 pm, Zayd C. removed_email_address@domain.invalid


#6

Master Chief wrote:

Being a newbie myself, I will add a word of caution.

Compare the version the book is based on, with what you are running. I
was on Rails 2.2.2 and its syntax for scaffold generation is different
from the earlier versions in the sense that the attributes are
expected in the command line now.

I learnt that the hard way.
So if you are using the latest and greatest, read the book with a
pinch of salt and check the net when in doubt!

Hope this helps.
I am using Rails 2.2.2 on Ruby 1.8.6 using MySQL 5.0 on WinXP. This
config just works for me.

Aside: Started off with Komodo and then jRuby on NetBeans IDE , using
MySQL 6.0 on Vista 64-bit but it was a mess cause half the time the
IDE was tripping me up and some gems/plugins wouldnt install
correctly. Dont know if it was because of Vista or NetBeans on 64-bit.
I had to use MySQL 6.0 as that is the only one which would run on
Vista 64-bit. but then some Rails stuff was not certified for mySQL
6.0 so ultimately I got out of that rat hole.

cheers
On Feb 19, 9:47�am, Frederick C. removed_email_address@domain.invalid

Thanks Guys that helped me out alot. I have the same set up. I’m also
using rails 2.2. Im not so proficient in the ruby language,I know how
to deal with arrays, hashes, code blocks, functions, basic stuff nothing
fancy at all. Should I be concentrating more on the ruby language
instead of moving so fast to rail projects?

Thanks


#7

RailsSpace was written with Rails 1.1.2 and Ruby 1.8.4 but there’s a
web site referenced in the book that makes the files for Rails 2
available. The site also has an ephemeris with corrections for the
code as printed in the book.

On Feb 19, 2:08 pm, Zayd C. removed_email_address@domain.invalid