- Rhomobile Beginner's Guide
- Abhishek Nalwaya
- 318字
- 2021-04-02 18:52:47
Creation of a new page
We will now add a new page manually in our employee application, which will list all the employee names and their respective designations.
Let us include following use-cases to make our application more interesting:
Time for action – Creation of the new page
We will now create a new page (employee_details.erb
) that will display the employee name and designation.
Follow these steps to create the page:
- Create an action
employee_details
inemployee_controller
. We write all the database queries using Rhom, which is an ORM of Rhodes:def employee_details @employee = Employee.find(:all) end
By adding
Employee.find(:all)
we will return an array of an object from the Employee Model. - Create a page
employee_details.erb
andemployee_details.bb.erb
in theEmployee
directory and add the following lines toemployee_details.erb
:<div class="pageTitle"> <h1>Employees Details</h1> </div> <div class="toolbar"> <div class="leftItem regularButton"> <a href="<%= Rho::RhoConfig.start_path %>">Home</a> </div> <div class="rightItem regularButton"> <a class="button" href="<%= url_for :action => :new %>">New</a> </div> </div> <div class="content"> <ul> <% @employees.each do |employee| %> <li> <a href="<%= url_for :action => :show, :id => employee.object %>"> <span class="title"><%= employee.name %> is <%= find_desigation(employee.age.to_i)%></span><span class="disclosure_indicator"></span> </a> </li> <% end %> </ul> </div>
- And, add these lines to
employee_details.bb.erb:
<div id="pageTitle"> <h1>Employees Details</h1> </div> <div id="toolbar"> <%= link_to "New", :action => :new %> <%= link_to "Home", RhoConfig::start_path %> </div> <div id="content"> <table> <tr> <% @employees.each do |obj| %> <td class="recordLabel"><%= link_to "#{obj.name} is #{find_desigation(obj.age.to_i)} ", :action => :show, :id => obj.object %></td> <% end %> </tr> </table> </div>
We have used a helper method find_designation, which returns the designation of that employee. This helper is created in the next step.
- Create a file
employee_helper.rb
in the helpers folder. - Include the
employee_helper
in controller so that it can be accessed in our view:require 'helpers/employee_helper' include EmployeeHelper Add the logic in employee_helper.rb which we created in the last section module EmployeeHelper def find_desigation age if age < 30= return "Developer" elsif age >= 30 and age < 40 return "Senior Developer" else return " Architect" end end end
- Edit
index.erb
file in app folder to add a link:<li> <a href="<%= url_for :controller => :Employee, :action => :employee_details %>"><span class="title"> Employee Details</span><span class="disclosure_indicator"/></a> </li>
- Edit
index.bb.erb
in the app folder and add a link to our page for Blackberry:<tr> <td class="recordLabel"> <%= link_to "Employee Details", :controller => :Employee, :action => :employee_details%> </td>
Now, build this code for iPhone as explained in this chapter earlier:
$rake run:iphone
- And similarly for Blackberry by:
$rake run:bb
We just created a new page in which the designation of employees are calculated on the basis of their age. We have also learnt how to write a helper method in our application.
- ModelSim電子系統分析及仿真(第3版)
- 中文版3ds Max 2016/VRay效果圖制作實戰基礎教程
- Excel 數據處理與分析實例教程(第2版)
- Creo Parametric 5.0中文版從入門到精通
- 老郵差數碼照片處理技法 圖層篇
- After Effects CC 2019 影視后期特效合成案例教程
- 中文版Rhino 5.0完全自學教程(第3版)
- Lighttpd
- 中文版Photoshop CS6全能修煉圣經(移動學習版)
- Mastercam 2019 完全自學寶典
- 電腦寫作與定制五筆(第2版)
- 數碼攝影修圖師完全手冊(第2卷)
- Photoshop CC 2015中文版實用教程(第7版)
- Illustrator 2024實用教程
- 同花順軟件操作技巧與實戰指南