Home Accessibility Courses Twitter The Mouth Facebook Resources Site Map About Us Contact
 
For 2023 (and 2024 ...) - we are now fully retired from IT training.
We have made many, many friends over 25 years of teaching about Python, Tcl, Perl, PHP, Lua, Java, C and C++ - and MySQL, Linux and Solaris/SunOS too. Our training notes are now very much out of date, but due to upward compatability most of our examples remain operational and even relevant ad you are welcome to make us if them "as seen" and at your own risk.

Lisa and I (Graham) now live in what was our training centre in Melksham - happy to meet with former delegates here - but do check ahead before coming round. We are far from inactive - rather, enjoying the times that we are retired but still healthy enough in mind and body to be active!

I am also active in many other area and still look after a lot of web sites - you can find an index ((here))
Really Simple Rails

Rails is a "Web Framwork" that uses code written in the Ruby language to do the things that vary from one web application to another. There are a huge number of features common to many web applications, and by using a framework you can save yourself the trouble of rewriting all these common things, using instead what's provided by Rails. It makes for quicker coding, a well thought out structure from the beginning, but (conversely) a whole lot of hooks and special names and terminologies that will leave the newcomer gasping for breath at first.

A very first demonstration of how the elements go together - see my previous blog [here] - about how examples can get overcomplicated before they're published. I don't pretend that this is useful in production, or clever, or even well structured - but it does show you how values from your model reach your view.

Background ... a new Rails application, installed and built using the Rails Installation Cheat Sheet I wrote a while back. That cheat sheet sets you up with a running new application that does nothing on rails.

Then set up
a) Application called "serverstats"
b) Controller called "summarise"
c) Model called "access"

  rails serverstats
  cd serverstats
  script/generate controller summarise
  script/generate model access ip:string pagename:string


Now - what URL do I use to browse to that? Answer: /summarise/ (and it will tell you there is no route). So I want to set up a controller and a view. See [here] for the directorys / files needed - and you only need the controller
  app/controllers/summarise_controller.rb
and the view
  app/views/summarise/index.erb
to start you off (in fact the index method in the controller can be empty at first, and the view template can contain just HTML).

The example code goes on to show you how you can add each of the following to your view
a) The standard (static) view
b) Data calculated in the view (you shouldn't do much of this)
c) Data to be displayed / calculated by the controller
d) Class data and application level information from a model
e) Database information provided through the model

For the database section to work, you'll want to add some seed values (see sample file) and you'll then need to:
  rake db:migrate
  rake db:seed
to set up and provide some initial test values in your database. Rails will default to SQLite.

Rails varies a bit from version 2 to 3 ... and at the time of writing, 4's on its way. At the end of our Ruby Programming Course we offer an optional Introduction to Ruby on Rails which will help you with your first steps into this framework, as in the example above.

(written 2013-02-17)

 
Associated topics are indexed as below, or enter http://melksh.am/nnnn for individual articles
R202 - Ruby on Rails
  [1050] The HTML++ Metalanguage - (2007-01-22)
  [1302] Ruby, Ruby, Ruby. Rails, Rails, Rails. - (2007-08-13)
  [1375] Python v Ruby - (2007-10-02)
  [1745] Moodle, Drupal, Django (and Rails) - (2008-08-08)
  [2605] Ruby on Rails - a sample application to teach you how - (2010-01-30)
  [2607] Answers on Ruby on Rails - (2010-01-30)
  [2609] Scope of variables - important to Ruby on Rails - (2010-01-31)
  [3624] Why do we need a Model, View, Controller architecture? - (2012-02-25)
  [3756] Ruby on Rails - how it flows, and where the files go - (2012-06-08)
  [3772] Hello World - Ruby on Rails - a checklist of each step - (2012-06-22)
  [3777] Multiple views in a single appication - sharing common parts of the template - Ruby on Rails - (2012-06-23)
  [3778] Providing a form to allow the user to add data to the model - Ruby on Rails - (2012-06-23)
  [3779] Adding validation to form entries and sticky fields - Ruby on Rails - (2012-06-23)
  [3780] Ruby of Rails - cleanly displaying model data in the view - (2012-06-23)
  [3919] What is a web framework? - (2012-11-10)
  [4013] Web Frameworks - nested templates - (2013-02-22)

Q915 - Object Orientation and General technical topics - Principles of Model - View - Controller
  [687] Presentation, Business and Persistence layers in Perl and PHP - (2006-04-17)
  [2199] Improving the structure of your early PHP programs - (2009-05-25)
  [2612] The Model, View, Controller architecture (MVC) - what, why and how. - (2010-02-01)
  [3237] Using functions to keep look and feel apart from calculations - simple C example - (2011-04-09)
  [3454] Your PHP website - how to factor and refactor to reduce growing pains - (2011-09-24)
  [3705] Django Training Courses - UK - (2012-04-23)
  [4066] MVC and Frameworks - a lesson from first principles in PHP - (2013-04-19)
  [4114] Teaching CodeIgniter - MVC and PHP - (2013-06-12)
  [4320] An example of Model-View-Controller techniques in a Perl / CGI script - (2014-11-20)
  [4391] Refactoring Perl applications to give them a rosy future - (2015-01-11)
  [4527] Hello Flask world / Python web micro framework - (2015-10-11)
  [4641] Using an MVC structure - even without a formal framework - (2016-02-07)
  [4691] Real life PHP application using our course training MVC example - (2016-06-05)


Back to
Clear, concise examples - Ruby classes and objects.
Previous and next
or
Horse's mouth home
Forward to
From Salford
Some other Articles
Costa Coffee in Melksham - is it a good idea?
A course is not just for a year - its for a career
From Salford
Really Simple Rails
Clear, concise examples - Ruby classes and objects.
Reading and checking user inputs - first lessons - Ruby
Which database should I use? MySQL v SQLite
Ruby / SQLite3 example program, showing JOIN v LEFT JOIN
New guest ... becoming returning guest
4759 posts, page by page
Link to page ... 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96 at 50 posts per page


This is a page archived from The Horse's Mouth at http://www.wellho.net/horse/ - the diary and writings of Graham Ellis. Every attempt was made to provide current information at the time the page was written, but things do move forward in our business - new software releases, price changes, new techniques. Please check back via our main site for current courses, prices, versions, etc - any mention of a price in "The Horse's Mouth" cannot be taken as an offer to supply at that price.

Link to Ezine home page (for reading).
Link to Blogging home page (to add comments).

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2024: 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho

PAGE: http://www.wellho.net/mouth/4010_.html • PAGE BUILT: Sun Oct 11 16:07:41 2020 • BUILD SYSTEM: JelliaJamb