• No results found

Introduction to Ruby on Rails

N/A
N/A
Protected

Academic year: 2021

Share "Introduction to Ruby on Rails"

Copied!
26
0
0
Show more ( Page)

Full text

(1)

Introduction to Ruby on Rails

Introduction to Ruby on Rails

Welcome to the puzzle….it’s a fun ride! Welcome to the puzzle….it’s a fun ride!

(2)

Terms you will hear

Terms you will hear

z Full stack

z Active Record

z Object Relational Model (ORM)

z MVC z Gems z RHTML z Migration z SVN z Full stack z Active Record

z Object Relational Model (ORM)

z MVC

z Gems

z RHTML z Migration

(3)

What is RoR?

What is RoR?

z It’s the next best thing to sliced bread? z It’s the silver bullet to fix our project? z It’s magic?

None of these things. It’s a tool. But it was conceived as a highly productive tool where DRY is paramount. Don’t Repeat Yourself.

z It’s the next best thing to sliced bread? z It’s the silver bullet to fix our project? z It’s magic?

None of these things. It’s a tool. But it was conceived as a highly productive tool where DRY is paramount. Don’t Repeat Yourself.

(4)

Things you will need

Things you will need

z Ruby (Language)

z Rails (Framework in Ruby) z Database

Start here: www.rubyonrails.org/down

You can download Instant Rails (Windows only). It contains Ruby, Rails, and MySQL for trying out the RoR world. You would use the command line and text editors to create applications.

z Ruby (Language)

z Rails (Framework in Ruby) z Database

Start here: www.rubyonrails.org/down

You can download Instant Rails (Windows only). It contains Ruby, Rails, and MySQL for trying out the RoR world. You would use the command line and text editors to create applications.

(5)

Available Development IDEs

Available Development IDEs

z RadRails – Eclipse-based, integrated

generators & servers.

http://www.radrails.org/

z TextMate – Mac oriented

http://www.macromates.com/

I use RadRails. Downside is that code generators are still command line. But that’s a minor drawback.

z RadRails – Eclipse-based, integrated

generators & servers.

http://www.radrails.org/

z TextMate – Mac oriented

http://www.macromates.com/

I use RadRails. Downside is that code generators are still command line. But that’s a minor drawback.

(6)

Source Code Repositories

Source Code Repositories

z CVS – Doesn’t seem to be the preferred

repository. Haven’t found an

integrated delivery system. I used

simple Ant scripts to build my delivery processes.

z SVN – Preferred repository and is

integrated with Capistrano. (Rails version of application delivery

systems.)

z CVS – Doesn’t seem to be the preferred

repository. Haven’t found an

integrated delivery system. I used

simple Ant scripts to build my delivery processes.

z SVN – Preferred repository and is

integrated with Capistrano. (Rails version of application delivery

(7)

After that…

After that…

The first place to start the journey is by

reading the article “Rolling with Ruby on Rails” by Curt Hibbs.

http://www.onlamp.com/pub/a/onlamp/20 05/01/20/rails.html

The first place to start the journey is by

reading the article “Rolling with Ruby on Rails” by Curt Hibbs.

http://www.onlamp.com/pub/a/onlamp/20 05/01/20/rails.html

(8)

Then what?

Then what?

You should pick up two books:

Agile Web Development with Rails

(Excellent)

Rails Recipes

(Great for finding specific functional modules you might need and having them running in an hour.)

You should pick up two books:

Agile Web Development with Rails

(Excellent)

Rails Recipes

(Great for finding specific

functional modules you might need and having them running in an hour.)

(9)

Other resources

Other resources

Rails online API

http://api.rubyonrails.org/

Ruby Forums

http://www.ruby-forum.com/user/login

RubyForge

http://rubyforge.org/ Rails online API

http://api.rubyonrails.org/

Ruby Forums

http://www.ruby-forum.com/user/login

RubyForge

(10)

On to Rails…

On to Rails…

z Object Relational Mapping: ActiveRecord

Like Java’s Hibernate (but simpler)

Takes away a lot of the drudgery associated with web applications.

(Create, Retrieve, Update, and Delete functions.)

z Object Relational Mapping: ActiveRecord

Like Java’s Hibernate (but simpler)

Takes away a lot of the drudgery associated with web applications.

(Create, Retrieve, Update, and Delete functions.)

(11)

Full Stack

Full Stack

J2EE Rails Webrick or Mongrel DispatchServlet RHTML ActionController ActiveRecord

Database Layer Database Layer

Hibernate Action Action

Form JSP

ActionServlet Tomcat Servlet Container

Yes…they are fairly comparable….

(12)

Or another way to put it

(13)

Or maybe this way…

(14)

Rails vs J2EE

Rails vs J2EE

z Both have a learning curve

z RAILS has the edge in productivity by a

significant margin.

z J2EE currently has an edge in scalability. If

it’s a client facing system for millions of concurrent users – use J2EE.

z If it’s an internal web application, definitely

take a look at this technology as a possible way of shortcutting the long development time for a J2EE web app.

z Both have a learning curve

z RAILS has the edge in productivity by a

significant margin.

z J2EE currently has an edge in scalability. If

it’s a client facing system for millions of concurrent users – use J2EE.

z If it’s an internal web application, definitely

take a look at this technology as a possible way of shortcutting the long development time for a J2EE web app.

(15)

Can’t afford the time to learn a new framework!!!

Can’t afford the time to learn a new framework!!!

z I needed a few screens to manage some dev data. Was investigating several

different technologies to see what would best serve the need and timeframe. (J2EE, Hibernate, JSF, Rails, etc)

z Day 1 - Picked up a Ruby On Rails book, read a few articles, started

experimenting.

z Day 2 - Stated building a few screens, relying on dynamic scaffolding for basic

CRUD functionality

z Day 3 - Began replacing scaffold screens with better looking ones by hand. z Day 4 – Started adding layouts, CCS, and some AJAX functionality to make

application a bit nicer.

z Day 5 – Began investigating Models, Migrations, and RJS templates to enhance

productivity.

5 days from start, over 50 screens produced, far more functionality than I had been planning, demos to multiple managers, and more than a few headaches. It’s not perfect, but is certainly a useful tool. (NOT A SILVER BULLET!!!!!!)

z I needed a few screens to manage some dev data. Was investigating several

different technologies to see what would best serve the need and timeframe. (J2EE, Hibernate, JSF, Rails, etc)

z Day 1 - Picked up a Ruby On Rails book, read a few articles, started

experimenting.

z Day 2 - Stated building a few screens, relying on dynamic scaffolding for basic

CRUD functionality

z Day 3 - Began replacing scaffold screens with better looking ones by hand. z Day 4 – Started adding layouts, CCS, and some AJAX functionality to make

application a bit nicer.

z Day 5 – Began investigating Models, Migrations, and RJS templates to enhance

productivity.

5 days from start, over 50 screens produced, far more functionality than I had been planning, demos to multiple managers, and more than a few headaches. It’s not perfect, but is certainly a useful tool. (NOT A SILVER BULLET!!!!!!)

(16)

Database

Database

z New term – Migration: A powerful and

flexible tool for managing database changes Allows table, index, and data creation scripts to be run in multiple environments with a very simple syntax.

Need to revert back to a previous DB version to work on a bug? 1 command. Then

refresh it back to the current dev version? 1 command.

z New term – Migration: A powerful and

flexible tool for managing database changes Allows table, index, and data creation scripts to be run in multiple environments with a very simple syntax.

Need to revert back to a previous DB version to work on a bug? 1 command. Then

refresh it back to the current dev version? 1 command.

(17)

Example Migration

Example Migration

class CreateMenuitems < ActiveRecord::Migration def self.up

# Create the Menuitems table. The ID field does not need to be specified – automagically created. create_table :menuitems do |t|

t.column :href, :string, :limit => 75 t.column :title, :string, :limit => 75 t.column :desc, :string, :limit => 75 t.column :leadtag, :string, :limit => 25 t.column :endtag, :string, :limit => 25

end

item = Menuitem.create(:href => "/menu/zero_dollars.html",

:title => "Zero dollar page1", :desc => "Zero dollar ads1", :leadtag => "<li>", :endtag => "</li>") item.save end def self.down drop_table :menuitems end end

class CreateMenuitems < ActiveRecord::Migration def self.up

# Create the Menuitems table. The ID field does not need to be specified – automagically created. create_table :menuitems do |t|

t.column :href, :string, :limit => 75 t.column :title, :string, :limit => 75 t.column :desc, :string, :limit => 75 t.column :leadtag, :string, :limit => 25 t.column :endtag, :string, :limit => 25

end

item = Menuitem.create(:href => "/menu/zero_dollars.html",

:title => "Zero dollar page1", :desc => "Zero dollar ads1", :leadtag => "<li>", :endtag => "</li>") item.save end def self.down drop_table :menuitems end end

(18)

MVC

MVC

z Model / View / Controller

Model

– Used for persistence and

relationships

View

– Used for displaying the data

Controller

– The logic of the application

z Model / View / Controller

Model

– Used for persistence and

relationships

View

– Used for displaying the data

(19)

Example Model

Example Model

class Node < ActiveRecord::Base end

Yes….that’s it. Rails queries the database and determines the datatypes and fields for you.

You can add data relationships, data validations to the model later. This is enough to get the scaffold screens up and running.

class Node < ActiveRecord::Base end

Yes….that’s it. Rails queries the database and determines the datatypes and fields for you.

You can add data relationships, data validations to the model later. This is enough to get the scaffold screens up and running.

(20)

Example View (With AJAX functionality thrown in)

Example View (With AJAX functionality thrown in)

<h1>Listing nodes</h1> <table> <tr> <th>Desc</th> <th>Create date</th> <th>Status</th> </tr> <% @nodes.each do |n| %> <tr> <td>

<%= @node = n; in_place_editor_field :node, :desc, {}, {:url => '/node/node_update_desc/' << @node.id.to_s,

:rows => 1, :cancelLink => 'false'} %>

</td>

<td width="50%" align="center"><%= n.created_at %></td> <td width="50%" align="center"><%= n.status %></td> </tr> <% end %> </table> <h1>Listing nodes</h1> <table> <tr> <th>Desc</th> <th>Create date</th> <th>Status</th> </tr> <% @nodes.each do |n| %> <tr> <td>

<%= @node = n; in_place_editor_field :node, :desc, {}, {:url => '/node/node_update_desc/' << @node.id.to_s, :rows => 1, :cancelLink => 'false'} %>

</td>

<td width="50%" align="center"><%= n.created_at %></td> <td width="50%" align="center"><%= n.status %></td> </tr>

<% end %> </table>

(21)

Example Controler

Example Controler

def list

@nodes = Node.find(:all) end

- Uses the ActiveRecord Object Relational

Mapping capabilities to pull all of the nodes in the Nodes table. No SQL written here to cause problems.

def list

@nodes = Node.find(:all) end

- Uses the ActiveRecord Object Relational

Mapping capabilities to pull all of the nodes in the Nodes table. No SQL written here to cause problems.

(22)

Rails/Ruby conventions

Rails/Ruby conventions

z Ruby Gems – Like Java Jar files. Packages

that can be installed. Taken one step further – simple installation methodologies.

z Convention over configuration. Use the

“Rails Way”. The framework is designed to make development fast and easy.

z RHTML - HTML files with embedded

Ruby/Rails code. Preprocessed into HTML z Ruby Gems – Like Java Jar files. Packages

that can be installed. Taken one step further – simple installation methodologies.

z Convention over configuration. Use the

“Rails Way”. The framework is designed to make development fast and easy.

z RHTML - HTML files with embedded

(23)

Resources

Resources

Rails API

http://api.rubyonrails.org/

CSS Menus

http://www.cssplay.co.uk/menus/index.html

Live DataGrid

http://unspace.ca/discover/datagrid/

Rails API

http://api.rubyonrails.org/

CSS Menus

http://www.cssplay.co.uk/menus/index.html

Live DataGrid

http://unspace.ca/discover/datagrid/

(24)

More…

More…

Subversion

http://subversion.tigris.org/

Data Relationships diagram

http://mboffin.com/stuff/ruby-on-rails-data-relationships.png Cheatsheets

http://www.rubyonrailsblog.com/files/RoRblog-CheatSheet.pdf

Subversion

http://subversion.tigris.org/

Data Relationships diagram

http://mboffin.com/stuff/ruby-on-rails-data-relationships.png

Cheatsheets

(25)

Cheatsheets

Cheatsheets

Migration http://garrettsnider.backpackit.com/pub/367902 Rails http://www.rubyonrailsblog.com/files/RoRblog-CheatSheet.pdf Webservices on Rails http://manuals.rubyonrails.com/read/book/10 WebCast How-To site

http://peepcode.com/ Migration http://garrettsnider.backpackit.com/pub/367902 Rails http://www.rubyonrailsblog.com/files/RoRblog-CheatSheet.pdf Webservices on Rails http://manuals.rubyonrails.com/read/book/10

WebCast How-To site

(26)

Summary

Summary

It’s an evolving toolset.

DRY leads to fewer lines of code. Less code should mean less chances for bugs.

Still requires normal analysis to be done on a project. But you can react far

quicker to changes in requirements. A great tool for your toolbox.

It’s an evolving toolset.

DRY leads to fewer lines of code. Less code should mean less chances for bugs.

Still requires normal analysis to be done on a project. But you can react far

quicker to changes in requirements. A great tool for your toolbox.

References

Related documents

o Växtföljden påverkade inte dragkraftsbehovet i någon större utsträckning. o Växtföljden hade stor inverkan på mängden skadegörare. Angreppsgraden var mycket högre i leden

For blending the different grand-cru coffee varieties offered by Nespresso, 32 bins holding 20 tons of coffee each are available.. There the green coffee beans await blending

Increasing the load capacity of the soil is possible by adjusting the irrigation regime (irrigation rate, intensity and diameter of rain drops, the amount of surface water

Abstract —This paper presents an overview of selected new modelling algorithms and capabilities in commercial software tools developed by TICRA. A major new area is design and

Recruiting Committee, (2007-2010) Strategic Management Department, IESE Business School, University of Navarra. MBA, Team

Using the Sustainable Family Business (SFB) model grounded in the systems theory, this study found out that of all the factors that affect sustainability, succession

The University of Iowa Hospitals and Clinics has about 100 pharmacists, including many who are involved in internal medicine and patient care issues that also involve pain

Hypothesis 2 proposes that closely related concepts compete for attention and thus the prevalence of an old concept should be negatively associated with the number of articles each

In the Webglimpse home page, for example, we add this term to the default formula to make sure that pages in the /docs directory appear first in the search results:. + ($LinkString

The trend of Fake News in a country like India is one of the most bothersome problem that has affected the Country’s Administration right from the freedom to

Based on data from the Irish Community Innovation Survey 2006-08, the results suggest that Irish-owned firms which engage in external networks with public knowledge sources,

RStudio has a nice feature: when you type rnorm( in the command window and press TAB, RStudio will show the possible arguments (Fig.. The following is a very sim- ple

accumulates in the kidney causing Itai-Itai disease. Like mercury, copper sulphate is also absorbed by shellfish which are thereby made unsuitable and even

The Database Administrator III is distinguished from the Database Administrator I, which performs entry level professional information technology work performing basic

– nwp_eccodes_grib_tools_inspect.ipynb – Using the GRIB tools to inspect GRIB messages – nwp_eccodes_grib_tools_modify.ipynb – Using the GRIB tools to modify GRIB messages

Complete machine tool expertise and support since 1968 Broad range of high quality and reputable machine tools Long standing relationships with machine tool suppliers..

Once queen cells have been started in the Swathmore or nucleus box, a queen right cell feeding or cell building hive is used to rear the queen cells to mature cell stage

In the mining industry competencies profiles shall be a supplement to qualifications, as they show a full characteristics of the employee, thus allowing the development of a precise

A pool of Faculty dedicated to your training, together with a wide case-mix will help you to master proper clinical examination of the eye and all its functions, management of

After exercising due diligence, the board or committee shall determine whether Nonprofit can obtain a more advantageous transaction or arrangement with reasonable efforts from a

The book is called Western Herbs for Martial Artists and Contact Athletes but it has a much broader appeal. I'm going to recommend it to every athlete I know. Actually, to