4. C in MVC
• Controller is responsible for making sense of the request and initiates
in the cycle to generate a appropriate output
• A middle man between models and views
• Makes the model data available to the view so it can display that
data to the user, and it saves or updates data from the
• REST
5. C in MVC cont…
• A controller is a Ruby class which inherits from ApplicationController
• ApplicationController inherits from ActionController::Base, which
defines a number of helpful methods
• Params Hash - query string & post data
• Eg: “GET /clients?id=1&name=Joe” params = {‘id’ => ‘1’, ‘name’ =>
‘Joe’}
8. V in MVC
• Views represent the user interface of your application.
• In Rails, views are often HTML files with embedded Ruby code that
perform tasks related solely to the presentation of the data.
• Views handle the job of providing data to the web browser
10. Directory Structure
class UserController <
ApplicationController
def show
@name = ‘John’
……
end
end
controllers/user_controller.rb
<h1>Hi this is <%= @name
%>.</h1>
views/users/show.html.erb