- Rhomobile Beginner's Guide
- Abhishek Nalwaya
- 578字
- 2021-04-02 18:52:47
Navigating the Directory Structure
As we have seen, Rhodes is smart enough to create the elementary folders and files for you. We will now understand the basic directory structure of a Rhodes application.
A Rhodes application has the following directories and files:
app
– This is the heart of your application, which contains the controllers, models, and views for your application.public
– This folder contains all the static files like stylesheet, JavaScript, and images for your application.rhoconfig.txt
– This file is used for configuring your application. We will discuss this in detail later in the book.build.yml
– This is a very important file for configuration as this contains all the configuration that is needed for building an application. It also contains your application name, version, vendor, etc. It has device SDKs, Rhodes location, and also the extensions that you are using in your application. We will discuss this in detail later in the book.Rakefile
– This file is used by Rhodes to execute the inbuilt rake commands.icon
– This folder will contain our application icon.
Now that your app is compiled and runs, you can start adding models and controllers. When the model is generated, Rhodes will also create files for a standard User Interface for displaying and editing the model. This follows the standard model-view-controller paradigm.
Time for action – Creating the model
Now, it's time to create the Model, View, and Controller for our employee application. We will create a model employee with attributes such as name, company, address, age, gender, and salary.
$ rhogen model employee name,company,address,age,gender,salary
The model generator will provide us with the following:
[ADDED] app/Employee/index.erb [ADDED] app/Employee/edit.erb [ADDED] app/Employee/new.erb [ADDED] app/Employee/show.erb [ADDED] app/Employee/index.bb.erb [ADDED] app/Employee/edit.bb.erb [ADDED] app/Employee/new.bb.erb [ADDED] app/Employee/show.bb.erb [ADDED] app/Employee/employee_controller.rb [ADDED] app/Employee/employee.rb [ADDED] app/test/employee_spec.rb
You will see that RhoGen creates a controller (employee_controller.rb
) and several HTML templates (.erb files
) for reading and editing objects for the specified model and we have seen the magic of the Rhogen model command. It has generated a lot of code for us. We can divide the generated code into four parts:
- Model: A model represents the information (data) of the application and the rules to manipulate that data. The file
employee.rb
is the model for employee application. It contains all the logic. - Controller: The controller provides the bond between the model and view. In Rhodes, the controller is responsible for processing incoming requests, interrogating the models for data, and passing that data on to the views for presentation. The file
employee_controller.rb
is the controller for employee application. - View: Views represent the user interface of your application. In Rhodes, views are often HTML files with embedded Ruby code that perform tasks related solely to the presentation of the data. These are
index.erb
,edit.erb
, etc. - Spec file: These are the files where we write unit test cases for our code. The file
employee_spec.rb
is the spec file for employee application.
If you look closely with a single rhogen
command, Rhodes has generated piles of files. You must be wondering what the uses for these files and folders are. Well, these files and folders are responsible for basic CRUD operations for your employee model. CRUD operations are CREATE, READ, UPDATE, and DELETE. If you have worked with Ruby on Rails, it is similar to the scaffold command.
What just happened?
We have created an employee model using the Rhogen command. Also, now we are familiar with CRUD operations and the logic behind them.
- 常用工具軟件案例教程
- Spring Web Flow 2 Web Development
- Mastering phpMyAdmin 3.3.x for Effective MySQL Management
- Dreamweaver CC實例教程(第5版·微課版)
- 邊做邊學:平面廣告設計與制作(Photoshop 2020+Illustrator 2020·第3版·微課版)
- PostgreSQL 9.0 High Performance
- Midjourney商業設計完全教程
- 中文版Flash CS6動畫制作(慕課版)
- 零基礎學Photoshop CS6(全視頻教學版)
- Python 3 Web Development Beginner's Guide
- Instant BlueStacks
- 中文版CorelDRAW X7完全自學教程(實例培訓教材版)
- NumPy 1.5 Beginner's Guide
- Illustrator 2022從入門到精通
- 跟著視頻學Excel數據處理:函數篇