link_to ruby on rails method

link_to helper method. 

Hello from rails.



It's now <%= @time %>


It's time to say
<%= link_to "GoodBye",say_goodbye_path %>!

Produces

Hello from rails.

It's now 2012-08-19 10:58:02 +0530
It's time to say GoodBye!

link_to first parameter is the text to be displayed in the hyperlink.
next parameter tells rails to generate the link to the goodbye action. 
GoodBye is the key word which got the link. 
say_goodbye_path == controller_view_path.

Note: Its not compulsory to have parentheses around method as in Java or other languages it is.  If you want you can have one.

In rails to print the output use <%= variable %>.  Note: Here =sign is important.  For normal computation use <% %> without = sign.

Model View Controller of Rails

Model = Database Related.  Responsible for maintaining the state of application. Can be Transient lasting for just a couple of interactions with the user or permanent and will be stored outside the application, often in the database. It enforces the constraints.  Business rules. For Example: Not to apply any discounts to order less then Rs. 50.  It act as a gatekeeper and a data store.

View =  User Interface based on the data in the model.  What will be displayed on the screen.  It gets the data from the model and format it properly and display it to the user. There can be different views that can display the same model data for different purpose.
Controller = Computation and getting value.  It receives input from the outside world(normally user input) interacts with the model and display an appropriate view to the user.

  1. Browser send the request.
  2. Controller interacts with model.
  3. Controller invokes view.
  4. View render next browser screen