What is the relationship between a framework like RoR and a database?

I’m a front end developer…I’ve never done ANY backend, although I did take a course in databases once. (I have a comp sci degree; I’m a competent programmer, I just haven’t done any backend web stuff before.)

So I’m trying to figure out how the framework relates to the database. Presumably they’re set up separately, and the framework receives requests from the website and sends them to the database, then receives the response and handles it appropriately to deliver the content correctly? It’s basically a complex intermediary for all the web-app logic? Am I far off?

Need a good explanation of this.

There are many possibilities to connect a web-app to a database (and a lot of different databases to choose from).

I think you should first consider the normal case (as e.g. most used in the RoR community):
a relational DB and a ORM (the object relational mapper – in RoR it is ActiveRecord based on the active record pattern).

a very high-level (and superficial) introduction:

  • the database is a separate entity and process.
  • the app defines models that describe both the tables in the relational database (RoR will create the necessary SQL commands) and the the way the data in the database can be accessed and modified from the web-app using objects and properties.
  • in your web-app-code you access the database only by interacting with those models. e.g. in RoR:
    1. the users make requests to the web-app
    2. the requests are handled in the controller.
    3. the controller creates or retrieves records (e.g. by invoking find(<id>) on the class object) from the DB. these records appear as objects (or arrays of objects).
    4. the controller modifies them, and
    5. stores the result back to the DB (e.g. by invoking save() on the object).
    6. the response e.g. shows the result to the user.

2

Presumably, as a front end developer, you know how your Rails controller handles standard HTTP requests. Rails MVP framework also has models. Rails has support for ActiveRecord models. These are basically classes that are linked to some underlining database. In your controller, you can make calls on this model to read or modify data in the database.

The way frameworks function in relation to the user’s request and the database is not very different from any tiny piece of code acting as an intermediary between the two. Any ‘web-app logic’ is situation between the two, be it a complex MVC/MVP framework or a 5 line PHP file. They function to determine the user’s request, make a connection to the database and retrieve stuff, and present this to the user.

A framework subdvidides several steps that often occur in this intermediary step. As the name implies MVP has Models that structure the data retrieved from the database in a useful way, a View where the end-result is given to the user, and a Presenter which ties these two together and may perform some additional logic.

Where as a website that doesn’t change can just serve static pages, a web application like amazon has got a lot to do to present a page that represents a product: put simply, it can retrieve the product details based on an identifier passed in and build a web page that displays those details.

I would say a web framework relates to a database in the following way:

“A web framework is used to build/run a program that requests from a webserver run to build responses that can use data stored in database.”

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật