Cloud 9 Adapt Project on Heroku (Week V), adaptheroku

Source: Internet
Author: User

Cloud 9 Adapt Project on Heroku (Week V), adaptheroku

Advanced Software Engineering

Week V

--------------- Write in front -------------------------

Https://moonsea.herokuapp.com/

Attach the link. This is the function to be implemented.

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

According to the instructor's requirements, it is strongly recommended to switch to Cloud 9, because it is the SaaS era, so we have to switch from the original Local to Cloud, and the experience is good, it is annoying to reconfigure all environments. Fortunately, with the previous Blog, configuration is not difficult. The next step is to clone the project and modify the source code.

1. Synchronize source code from github

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

2. Go to the source code and install bundle.

1 cd zsmjzlb2 bundle install

At this time, there may be various Problems, the most common is to prompt the lack of a dependency package, just install as prompted, you can refer to "Some Problems about Gem ".

3. migrate the database after installing

1 rake db:migrate2 rake db:seed

4. After the database is migrated, run

Because it is on cloud 9, use the following command

1 rails s -p $PORT -b $IP

------------------------- Modification requirements -------------------------------

Function 1. Click to sort titles (click, forward; click again, backward)

Function 2. Achieve title yellowing

Function 3. Add the check box to select the query function.

------------------------ Enter the topic ---------------------------------

Because ruby on rails is a system using the MVC framework, to implement a function, we usually need) three layers for modification implementation.

================= Function 1 ======================================

(1), v(view)layer, modify the front-end display effect of the page, and add a link to the title (title, release date) in the response index.html. haml file to enable click sorting.

 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     - else11       %th= link_to "Release Date", movies_path(:selectsort=> "release_date", :sort=> @sorted, :ratings=> params[:ratings])12     %th More Info

(2) then, on the C (controller) layer, add the sorting function in the "movies_controller.rb" file. Because the two clicks are sorted differently, add the flag (sorted ), sorted = 1 reverse order, sorted = 0 order

 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 == 110         @movies = @movies.reverse11         @sorted = 012       else13         @sorted = 114       end15     end16   end

(3) M (model) layer. This function does not use the model layer, so you do not need to modify it.

(4) Save and run the following command for access.

1 rails s -p $PORT -b $IP

===================== Function 2 ================================== ===

The title click turns yellow, which is implemented by the css style.

In feature 1, the click sorting function is implemented through "th. hilite", so you only need to change the background color of this label to yellow in the css file. Add the following code to the "default. ss" file:

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

================= Function 3 ==================================== ====

Select and query different ratring levels

(1) Add the following code to the overview index.html. haml page of v(viewpager layer:

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

(2) then, at the C (controller) layer, add the following code to the index function of the "movies_controller.rb" file:

1 @all_ratings = Movie.ratingcollection2     if params[:ratings]3       @ratings = params[:ratings].keys4     else5       @ratings = @all_ratings6     end7     8     @movies = Movie.where(rating: @ratings)

(3) At the end, the M (model) layer implements the query function in the "movie. rb" file. The Code is as follows:

1 def Movie.ratingcollection2         ratingcollect = Array.new3         i = 04         Movie.select(:rating).distinct.each do |movie|5             ratingcollect[i] = movie.rating6             i += 1;7         end8         return ratingcollect.sort9     end

(4) Save and run access.

Now, all functions are required.

Next, Deploy the project to Heroku. For more information, see Deploy One Project on Heroku (Week IV )".

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.