CSC/ECE 517 Fall 2012/ch1b 1w64 nn: Difference between revisions

From Expertiza_Wiki
Jump to navigation Jump to search
Line 6: Line 6:
*  Ensure there is something for the action to render in app/views/model/action.html.haml. You have to assure that there is something to the action can render what its all done. Every trip through the controller has to end with returning something and will see that although the most common thing is returning a view whose name matches the controller action, we can also return other things.
*  Ensure there is something for the action to render in app/views/model/action.html.haml. You have to assure that there is something to the action can render what its all done. Every trip through the controller has to end with returning something and will see that although the most common thing is returning a view whose name matches the controller action, we can also return other things.
===MVC responsibilities===
===MVC responsibilities===
* Model: methods to get/manipulate data
* Model: methods to get/manipulate data <pre>
<pre>
Movie.where(...), Movie.find(...)
Movie.where(...), Movie.find(...)
</pre>Different methods are providede by active record to do that.
</pre>Different methods are providede by active record to do that.
Line 17: Line 16:
</pre>
</pre>
*View:  display data, allow user interaction. Show details of a movie (description, rating)
*View:  display data, allow user interaction. Show details of a movie (description, rating)
===URI helpers===
===URI helpers===
===References===
===References===

Revision as of 03:05, 29 September 2012

SaaS - 3.12 Controller and views

Introduction

Adding a new controller action to Rails application

  • Create route in config/routes.rb if needed. Make sure that there is a route that is going to eventually route action, if not create one in routes.rb.
  • Add the action method) in the appropriate app/controllers/*_controller.rb. You have to add the actual code in other words, the method in the appropriate controler file that will do whatever that action is.
  • Ensure there is something for the action to render in app/views/model/action.html.haml. You have to assure that there is something to the action can render what its all done. Every trip through the controller has to end with returning something and will see that although the most common thing is returning a view whose name matches the controller action, we can also return other things.

MVC responsibilities

  • Model: methods to get/manipulate data

Movie.where(...), Movie.find(...)

Different methods are providede by active record to do that.

  • Controller: get data from Model, make available to View
def show
  @movie = Movie.find(params[:id])
end
  • View: display data, allow user interaction. Show details of a movie (description, rating)

URI helpers

References