firstruby

Master ruby with us

C. Intermediate::Rails

What is Rails ? its Installation,

Rails is an open-source web application framework written in Ruby that closely follows the Model-View-Controller ( M-V-C ) architecture, it is also called as Ruby on Rails(RoR). It is for developing database web applications. It strives for simplicity and allowing real-world applications to be developed in less code than other frameworks and with a minimum of configuration.

It uses two important concepts : CoC and DRY.

CoC stands for “Convention over Configuratio”. Convention over Configuration” means a developer only needs to specify unconventional aspects of the application. For example, if there’s a class Sale in the model, the corresponding table in the database is called sales by default.

DRY stands for “Don’t Repeat Youeself”, means every piece of information should be placed at one place only.

Rails design follows M-V-C architecture,

Model: The model is responsible for maintaining the state of the application. Sometimes this state is transient, lasting for just a couple of interactions with the user. Sometimes the state is permanent and will be stored outside the application, often in a database. A model is more than just data; it enforces all the business rules that apply to that data. and make sure that nothing else in the application can make our data invalid.

View: The view is responsible for generating a user interface, normally based on data in the model. Although the view may present the user with various ways of inputting data, the view itself never handles incoming data. The view’s work is done once the data is displayed. There may be many views that access the same model data, often for different purposes.

Controller: Controllers handles web request from user, receives requests from the outside world (normally user input), interact with the model, and display an appropriate view to the user.

MVC Architecture follows by RoR

Rails Installation

  • Ruby must be installed for rails installation.
  • Check for gem installation by typing gem –version in a command window.
  • Now we will use RubyGems to install Rails.
      Check whether your internet connection is active.

    In a command window, type gem install rails –include-dependencies

  • Now you are ready to run rails(RoR).
  • To update your rails application, simply type gem update rails in command window. This will automatically update your rails installation.
  • Getting Started with a New Rails Application

  • Create new Rails application by the command rails <app-name>, like c:\>rails demo
  • This will automatically create rails application name ‘demo’ with standard directory structure.
  • Change directory to c:\>cd demo, then Start WEBrick server by the command c:\demo>ruby script/server . Then access http://localhost:3000 in the browser, you should see a screen that looks like this.
  • Welcome aboard

  • This confirms that the installation was successful and Rails is running.
  • 2 Responses to “C. Intermediate::Rails”

    1. migera said

      ford fort lauderdale

    2. […] C. Intermediate::Rails […]

    Leave a Reply

    Fill in your details below or click an icon to log in:

    WordPress.com Logo

    You are commenting using your WordPress.com account. Log Out / Change )

    Twitter picture

    You are commenting using your Twitter account. Log Out / Change )

    Facebook photo

    You are commenting using your Facebook account. Log Out / Change )

    Google+ photo

    You are commenting using your Google+ account. Log Out / Change )

    Connecting to %s

     
    %d bloggers like this: