Installing Rails:
$ gem install rails
Creating You Application (let's call it myblog)
$ rails new myblog
This will create a new folder with some stuff in there, i.e. your project folder.
To Run the Rails Server
$ rails server
What Are Rails Generators?
$ rails generate --help
Usage: rails generate GENERATOR [args] [options]
You can watch this Webcast about Rails3 Generators and then come back here l8r...
Types of Generators:
Rails:
assets
controller
generator
helper
integration_test
mailer
migration
model
observer
performance_test
resource
scaffold
scaffold_controller
session_migration
task
Coffee:
coffee:assets
Jquery:
jquery:install
Js:
js:assets
Generating Controller:
$ rails generate controller --help
$ rails generate controller CreditCard open debit credit close
Description:
Stubs out a new controller and its views. Pass the controller name, either CamelCased or under_scored, and a list of views as arguments.
To create a controller within a module, specify the controller name as a path like 'parent_module/controller_name'.
This generates a controller class in app/controllers and invokes helper, template engine and test framework generators.
Example:
`rails generate controller CreditCard open debit credit close`
Credit card controller with URLs like /credit_card/debit.
Controller: app/controllers/credit_card_controller.rb
Functional Test: test/functional/credit_card_controller_test.rb
Views: app/views/credit_card/debit.html.erb [...]
Helper: app/helpers/credit_card_helper.rb
Scaffold Generator
$ rails generate scaffold --help
Usage:
rails generate scaffold NAME [field[:type][:index] field[:type][:index]] [optons]
Description:
According to Wikipedia, Scaffolding is a technique supported by some model-view-controller frameworks, in which the programmer may write a specification that describes how the application database may be used. The compiler uses this specification to generate code that the application can use to create, read, update and delete database entries, effectively treating the template as a "scaffold" on which to build a more powerful application. [I.e. It creates tables, fields, and web forms to edit those tables, etc.]
Scaffolds an entire resource, from Model and Migration to Controller and Views, along with a full test suite. The resource is ready to use as a starting point for your RESTful, resource-oriented application.
Pass the name of the model (in singular form), either CamelCased or under_scored, as the first argument, and an optional list of attribute pairs.
Attributes are field arguments specifying the model's attributes. You can optionally pass the type and an index to each field. For instance: "title body:text tracking_id:integer:uniq" will generate a title field of string type, a body with text type and a tracking_id as an integer with an unique index. "index" could also be given instead of "uniq" if one desire a non unique index.
Database
# Database configuration are stored in
config/database.yml
# To create the actual database, use the following commnad:
$
rake db:create
Gemfiles [In Application Home Directory]
Gemfile (and Gemfile.lock): These files allow you to specify what gem dependencies are needed for your Rails application.
$ bundle install # Use this command to install newly added gems
Some Ruby Tips
Since I don't speak ruby, here are some things I stumbled upon today
$myVar ==> Global Variable.
:myVar ==> I have no idea what's that, they call it Symbol, looks like constant string or something.
That's all folks for today.
No comments:
Post a Comment