I am only providing some key information that will be helpful in other projects.
Creating the Model
$rails generate model Article
This will create a model and a database named article. To add rows in the db we have to edit the db/migrate.*.rb file. Then again migrating the database with rake will create a database table with the given fields.
After creating the models we can add data to the db and also check the model in interactive mode my typing
$rails console
Relationship between different db models can be shown by
>has_one
>has_many
>belongs_to
>has_and_belongs_to_many
Generating the controller
$rails generate controller article
It generate a controller named ArticleController in app/controller. We can add our template files for the corresponding controller in app/view/articles. We also have to change the route.rb file in config corresponding to the model and controller.
Scaffolding is one of the important feature of rails. Scaffolding helps to create a set of actions and templates that makes it easy to manipulate data for a specific model.
Creating the View
There is no need to create or generate a view. At the time of generating the controller a view is also generated. We can add CSS to the file inside app/views/layouts which can be applied to view of each page.
You can find the code in http://github.com/omalbastin/logu
and run it on http://logu.heroku.com/
Showing posts with label LogU. Show all posts
Showing posts with label LogU. Show all posts
Saturday, October 2, 2010
LogU - My Blog Application
Rails Framework
Rails is a web application framework for the Ruby programming language. It is a powerful application which can be used to build web sites quickly and easy to maintain. A framework is a collection of libraries and tools for the development of an application. A good framework provide complete infrastructure to build our application. Rails is a open source, platform independent framework.
Here in rails it has only less codes and using conventions over configuration. It is simple compared to other framework but little difficult to play with all the conventions.
Rails uses the MVC pattern, which divides the application logic and pass it to three separate entities- Model(data), View(user interface), Controller(all other actions). Changing any of the entity will not affect other entities.
A user interact with the interface and provide a form submission. The controller receives this input and pass it to the model, model provides the information according to the form and return it to the controller and pass it to the view and it provides the user interface and pass it to the user.
The three main library that map directly to MVC are 1.Active Record- which handles the database, 2.Action view- which generates the HTML documents and 3.Action Controller that controls the database and application flow.
Installation
Type in your terminal:
$ sudo apt-get install build-essential libssl-dev libreadline5 libreadline5-dev zlib1g zlib1g-dev
Download ruby and mkdir ~/src && cd ~/src
$wget ftp://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.1-p376.tar.gz
$tar -zxvf ruby-1.9.1-p376.tar.gz
$cd ruby-1.9.1-p376
$./configure && make && sudo make install
$sudo gem install rails
$sudo gem update --system
$sudo gem update rails
$sudo gem install sqlite3-ruby
Creating the Application
$rails new blog
$bundle install
To run the server go to the my_app folder and
$rails server
With the server running, if you open http://localhost:3000/ in your browser, you see the Rails welcome page.
To create our project database
$rake db:create
Rake is a build language for ruby. By calling rake db:create we are creating database for development environment only. For creating all the databases needed for the rails application type,
$rake db:create:all
This will create databases for testing and production environment.
$rails db:migrate
This will connect our rails application to the database.
Rails is a web application framework for the Ruby programming language. It is a powerful application which can be used to build web sites quickly and easy to maintain. A framework is a collection of libraries and tools for the development of an application. A good framework provide complete infrastructure to build our application. Rails is a open source, platform independent framework.
Here in rails it has only less codes and using conventions over configuration. It is simple compared to other framework but little difficult to play with all the conventions.
Rails uses the MVC pattern, which divides the application logic and pass it to three separate entities- Model(data), View(user interface), Controller(all other actions). Changing any of the entity will not affect other entities.
A user interact with the interface and provide a form submission. The controller receives this input and pass it to the model, model provides the information according to the form and return it to the controller and pass it to the view and it provides the user interface and pass it to the user.
The three main library that map directly to MVC are 1.Active Record- which handles the database, 2.Action view- which generates the HTML documents and 3.Action Controller that controls the database and application flow.
Installation
Type in your terminal:
$ sudo apt-get install build-essential libssl-dev libreadline5 libreadline5-dev zlib1g zlib1g-dev
Download ruby and mkdir ~/src && cd ~/src
$wget ftp://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.1-p376.tar.gz
$tar -zxvf ruby-1.9.1-p376.tar.gz
$cd ruby-1.9.1-p376
$./configure && make && sudo make install
$sudo gem install rails
$sudo gem update --system
$sudo gem update rails
$sudo gem install sqlite3-ruby
Creating the Application
$rails new blog
$bundle install
To run the server go to the my_app folder and
$rails server
With the server running, if you open http://localhost:3000/ in your browser, you see the Rails welcome page.
To create our project database
$rake db:create
Rake is a build language for ruby. By calling rake db:create we are creating database for development environment only. For creating all the databases needed for the rails application type,
$rake db:create:all
This will create databases for testing and production environment.
$rails db:migrate
This will connect our rails application to the database.
Labels:
LogU
Subscribe to:
Posts (Atom)