#apt-get install ruby rails
--
HASTA LA VICTORIA SIEMPRE!
#!/usr/bin/ruby -w
puts "Hello World"
x = "How are you?"
puts x
#from inside ~/code/ruby - to create a new project named blog, it will create a directory named blog and few files in it. This will create a Rails application that uses a SQLite database for
data storage. If you prefer to use MySQL, run this command instead:
$ rails blog -d mysql
And if you’re using PostgreSQL for data storage, run this command:
$ rails blog -d postgresql
TIP. You can see all of the switches that the Rails application builder accepts by running rails -h.
After you create the blog application, switch to its folder to continue work directly in that application:
$ cd blog
In any case, Rails will create a folder in your working directory called blog. Open up that folder and explore its contents.
| File/Folder | Purpose |
|---|---|
| README | This is a brief instruction manual for your application. Use it to tell others what your application does, how to set it up, and so on. |
| Rakefile | This file contains batch jobs that can be run from the terminal. |
| app/ | Contains the controllers, models, and views for your application. You’ll focus on this folder for the remainder of this guide. |
| config/ | Configure your application’s runtime rules, routes, database, and more. |
| db/ | Shows your current database schema, as well as the database migrations. You’ll learn about migrations shortly. |
| doc/ | In-depth documentation for your application. |
| lib/ | Extended modules for your application (not covered in this guide). |
| log/ | Application log files. |
| public/ | The only folder seen to the world as-is. This is where your images, javascript, stylesheets (CSS), and other static files go. |
| script/ | Scripts provided by Rails to do recurring tasks, such as benchmarking, plugin installation, and starting the console or the web server. |
| test/ | Unit tests, fixtures, and other test apparatus. These are covered in Testing Rails Applications |
| tmp/ | Temporary files |
| vendor/ | A place for third-party code. In a typical Rails application, this includes Ruby Gems, the Rails source code (if you install it into your project) and plugins containing additional prepackaged functionality. |
One of the traditional places to start with a new language is by getting some text up on screen quickly. To do that in Rails, you need to create at minimum a controller and a view. Fortunately, you can do that in a single command. Enter this command in your terminal:
$ script/generate controller home index
TIP. If you’re on Windows, or your Ruby is set up in some non-standard fashion, you may need to explicitly pass Rails script commands to Ruby: ruby script/generate controller home index.
Rails will create several files for you, including app/views/home/index.html.erb. This is the template that will be used to display the results of the index action (method) in the home controller. Open this file in your text editor and edit it to contain a single line of code:
<h1>Hello, Rails!</h1>
You actually have a functional Rails application already – after running only two commands! To see it, you need to start a web server on your development machine. You can do this by running another command:
$ script/server
This will fire up an instance of the Mongrel web server by default (Rails can also use several other web servers). To see your application in action, open a browser window and navigate to http://localhost:3000. You should see Rails’ default information page
The “Welcome Aboard” page is the smoke test for a new Rails application: it makes sure that you have your software configured correctly enough to serve a page. To view the page you just created, navigate to http://localhost:3000/home/index.Great effort Anoop. I'm guessing that others in our group are also
trying it out even if they are not mailing to the list.
If any of you think that a pre-workshop session is required, we can
arrange for that.
James