File: topic/show.rhtml

quaggahooliganInternet και Εφαρμογές Web

5 Φεβ 2013 (πριν από 4 χρόνια και 4 μήνες)

110 εμφανίσεις

Robin Hu

Corey Jansen

John Gibson


Ruby on Rails is a web development
framework.


Well suited for AGILE development.


Uses the Ruby programming language.


Uses the Model
-
View
-
Controller (MVC)
design pattern.


Favors “Convention over Configuration”.



Things you can build with Ruby on Rails:


Any database driven web application.


Web forum.


Blog.


Phonebook.


Content management system.


Accounting.



Server machine.


Install Ruby


Install Rails


Install MySQL


Frontend uses: HTML + CSS + Javascript.


Backend uses: Ruby + Rails framework.



Model
:

Describes data
relations

Interfaces with DB

Controller:

Processes data

Serves client
requests

View:

Display data to
client


Defines how data is related to each other.


Model acts as interface to database.


Get all topics:

Topic.find(:all)


Find topic by ID:

Topic.find(35)


New Topic:


Topic.new


Destroy Topic:

Topic.find(35).destroy


User visits:

http://localhost:3000/topics/show/1

domain

controller

action

parameters

Class TopicsController


Def list


@topics = Topic.find(:all)

End


Def show


@topic = Topic.find(params[:id])

End


When controller is finished, the
processed data is sent to an RHTML file.


User visits:
http://localhost:3000/topics/show/1

Controller executes:
@topic =
Topic.find
(1)

File: topic/
show.rhtml

<html>


<body>



<%= @
topic.name

%>


</body>

</html>





Scaffolding is the process of generating
files for the model, controller and views
for an entity in one step.


Done on the command line.




A migration is a change made to the
database.


Altering a database can be done in Rails
(e.g.,
add_column(:topic,:date_created,:date)


The changes are kept in Ruby files.


Allows a team of developers to keep local
databases in sync.


Acts as a form of version control.


Rails comes with hundreds of functions to
ease web development.


Functions to generate HTML code (e.g.,
text_field()
).


Date/Time functions(e.g.,
30.days.from_now
).


Cookie/session variables stored in
global arrays.




Powerful, high level programming
language.


Arrays:
[5,6,10,1,9,12].sort


Regular Expressions:
“hello” =~ /[l]*/


String functions: searching, slicing,
substring replacement.


Array functions: sorting, searching,
collect, join, insert, delete.


http://www.rubyonrails.com