设为首页 加入收藏

TOP

Cloud 9 Adapt Project on Heroku (Week V)(一)
2017-10-09 13:49:39 】 浏览:10004
Tags:Cloud Adapt Project Heroku Week

Advanced Software Engineering

Week V

--------------- 写在前面 -------------------------

https://moonsea.herokuapp.com/

附上链接,这个是要实现的功能

-------------------------------------------------------------

根据老师上课的要求,强烈建议更换到Cloud 9, 因为是SaaS时代,所以只好从原来的Local转换到Cloud,用起来体验还不错,只是各种环境都需要重新配置,比较烦。还好,有了之前的Blog,配置起来也不是什么难事.接下来就是git clone项目,修改源码。

1.从github同步源码

1 git clone https://github.com/zsmjzlb/zsmjzlb.git

2.进入源码,进行bundle install

1 cd zsmjzlb
2 bundle install

这时候,可能会出现各种问题,最常见的就是提示缺少某个依赖包,只需要根据提示进行安装即可,可以参照"Some Problems about Gem"。

3.install之后,进行数据库迁移

1 rake db:migrate
2 rake db:seed

4.数据库迁移之后,运行

因为是在cloud 9 上,所以使用如下命令

1 rails s -p $PORT -b $IP

-------------------------修改要求-------------------------------

功能1.实现标题点击排序(点击,正序;再点击,逆序)

功能2.实现标题点击变黄

功能3.加入复选框,实现选择查询功能

------------------------进入正题---------------------------------

 因为ruby on rails 是采用MVC框架的一种系统,所以实现一个功能,一般需要从M(model)、V(view)、C(controller)三个层次进行修改实现。

=============  功能1 =======================

(1)首先,V(view)层,修改页面前端显示效果,在”index.html.haml“文件中给标题(title、release date)添加链接,实现点击排序功能

 1  %thead
 2     %tr
 3     - if @selectsort == "title"
 4       %th.hilite= link_to "Movie Title", movies_path(:selectsort=>"title", :sort=>@sorted, :ratings=>params[:ratings])
 5     - else
 6       %th= link_to "Movie Title", movies_path(:selectsort=>"title", :sort=>@sorted, :ratings=>params[:ratings])
 7     %th Rating
 8     - if @selectsort == "release_date"
 9       %th.hilite= link_to "Release Date", movies_path(:selectsort=> "release_date", :sort=> @sorted, :ratings=> params[:ratings])
10     - else
11       %th= link_to "Release Date", movies_path(:selectsort=> "release_date", :sort=> @sorted, :ratings=> params[:ratings])
12     %th More Info

(2)然后,C(controller)层,在“movies_controller.rb”文件中,添加排序的功能,因为两次点击排序不同,所以加入flag(sorted),sorted =1 逆序,sorted =0 顺序

 1 def index
 2     @movies = Movie.all
 3     
 4     @sorted = 0
 5     @selectsort = "waitparams"
 6     if params[:selectsort]
 7       @selectsort = params[:selectsort]
 8       @movies = @movies.sort_by{|movie| movie[@selectsort]}
 9       if params[:sort].to_i == 1
10         @movies = @movies.reverse
11         @sorted = 0
12       else
13         @sorted = 1
14       end
15     end
16   end

(3)M(model)层,这个功能没有用到model层,所以不需要修改

(4)保存,使用如下命令运行访问即可。

1 rails s -p $PORT -b $IP

=============== 功能2 ==========================

实现标题点击变黄,是由css样式来实现的。

因为在功能1中,是通过"th.hilite"来实现点击排序功能,所以只需要在css文件中,将这个标签的背景颜色变成黄色就可以。"default.ss"文件中加入如下代码:

1 table#movies th.hilite {
2     background-color: yellow
3 }

============= 功能3 =============================

实现不同ratring等级的选择查询

(1)首先,V(view)层,在“index.html.haml”页面中加入如下代码

1 -# checkbox
2 =form_tag movies_path, :method => :get do 
3   Rating Rank:
4   - @all_ratings.each do |rating|
5     = rating
6     = check_box_tag "ratings[#{rating}]","1",(@ratings.include? rating)
7   = check_box_tag "ratings[hidden]","1",true,hidden:true
8   = submit_tag "Refresh"

(2)然后,C(controller)层,在“movies_controller.rb”文件的index函数中,加入如下代码

1 @all_ratings = Movie.ratingcollection
2     if params[:ratings]
3       @ratings = params[:ratings].ke
首页 上一页 1 2 下一页 尾页 1/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇ubuntu15.04安装 RVM 下一篇self_vs_default_definee_vs_rece..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目