First of all navigate to the folder where we wanted to create our application in console then in the console paste the above command
mathew@mathew Aptana RadRails Workspace]$ rails cric
The result will be as below
[mathew@mathew Aptana RadRails Workspace]$ rails cric
create
create app/controllers
create app/helpers
create app/models
create app/views/layouts
create config/environments
create config/initializers
create config/locales
create db
create doc
create lib
create lib/tasks
create log
create public/images
create public/javascripts
create public/stylesheets
create script/performance
create test/fixtures
create test/functional
create test/integration
create test/performance
create test/unit
create vendor
create vendor/plugins
create tmp/sessions
create tmp/sockets
create tmp/cache
create tmp/pids
create Rakefile
create README
create app/controllers/application_controller.rb
create app/helpers/application_helper.rb
create config/database.yml
create config/routes.rb
create config/locales/en.yml
create db/seeds.rb
create config/initializers/backtrace_silencers.rb
create config/initializers/inflections.rb
create config/initializers/mime_types.rb
create config/initializers/new_rails_defaults.rb
create config/initializers/session_store.rb
create config/environment.rb
create config/boot.rb
create config/environments/production.rb
create config/environments/development.rb
create config/environments/test.rb
create script/about
create script/console
create script/dbconsole
create script/destroy
create script/generate
create script/runner
create script/server
create script/plugin
create script/performance/benchmarker
create script/performance/profiler
create test/test_helper.rb
create test/performance/browsing_test.rb
create public/404.html
create public/422.html
create public/500.html
create public/index.html
create public/favicon.ico
create public/robots.txt
create public/images/rails.png
create public/javascripts/prototype.js
create public/javascripts/effects.js
create public/javascripts/dragdrop.js
create public/javascripts/controls.js
create public/javascripts/application.js
create doc/README_FOR_APP
create log/server.log
create log/production.log
create log/development.log
create log/test.log
This will create a bunch of files as given above.So our next step to navigate to that project folder by giving the below command.
mathew@mathew Aptana RadRails Workspace]$ cd cric/
Inorder to check whether rails applicaion is set to work use the below command to start the server
[mathew@mathew cric]$ script/serverYou can see this results on the console panel
[mathew@mathew cric]$ script/server
=> Booting WEBrick
=> Rails 2.3.4 application starting on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
[2010-10-18 15:33:16] INFO WEBrick 1.3.1
[2010-10-18 15:33:16] INFO ruby 1.8.6 (2007-09-24) [i386-linux]
[2010-10-18 15:33:16] INFO WEBrick::HTTPServer#start: pid=3435 port=3000
Since there is no error on console u can check the application by goin through this url http://localhost:3000/
The following screen appears infront of you
For all those who are beginner in programming aim to show Hallo world first,so lets also begin like that. So first of all lets start by creating controller Also our main aim is to create a team management system so we need to create a table to store the name of the team along with their ids.So the first step is to write a model called team.So go to the projects folder and run this below script to create a model for team.mathew@mathew cric]$ script/generate model team
If the model is created successfully the following sub folders should be also createdas below
exists app/models/
exists test/unit/
exists test/fixtures/
create app/models/team.rb
create test/unit/team_test.rb
create test/fixtures/teams.yml
create db/migrate
create db/migrate/20101021043114_create_teams.rb
As a result of this migrations are created so what we need is to run a migration by mentioning the fields of the table teams in the migration file as below
class CreateTeams < limit ="">32 t.string :group, :limit =>32 t.timestamps end end def self.down drop_table :teams end end
After making proper changes to migrations save the migrations and we need to rake the migration in order to create the table called "teams".So use the below command to rake the migration
[mathew@mathew cric]$ rake db:migrate
If the migration is a successful one the result will be like this as below
[mathew@mathew cric]$ rake db:migrate
(in /home/mathew/Aptana RadRails Workspace/cric)
== CreateTeams: migrating ====================================================
-- create_table(:teams)
-> 0.2117s
== CreateTeams: migrated (0.2126s) ===========================================
So table is created,our next step is to print "hallo world",i think i had forgotten that, so next we need to create a controller to write our first method through which i can show you hallo world
Inorder to create a controller use the below command on the console,here admins is the name of the controller
mathew@mathew cric]$ script/generate controller admins
If it is created successfully we will get the below result on the console
mathew@mathew cric]$ script/generate controller adminsexists app/controllers/
exists app/helpers/
create app/views/admins
exists test/functional/
create test/unit/helpers/
create app/controllers/admins_controller.rb
create test/functional/admins_controller_test.rb
create app/helpers/admins_helper.rb
create test/unit/helpers/admins_helper_test.rb
Then open the routes.rb and make an entry like this below
map.resources :admins
This is where exact mapping take place.
Then go to the controller and write one method called index as given belowdef index puts"jasssssssssssssssssssssssssssssss" end
Then create a view file called index.html.erb and write a label like this
>label<Hallo world>/label<
Then start the server by giving the below command
[mathew@mathew cric]$ script/server
Then give the following link in browser ans see the result
http://0.0.0.0:3001/admins SO Our first second wish come true.
No comments:
Post a Comment