我一直在研究 Edx 问题 Homeowrk 2 大约 2 小时。我正式卡住了。你怎么做东西。这个问题与
我要做的是将电影标题链接到排序,以便它按顺序对电影进行排序。
-# This file is app/views/movies/index.html.haml
%h1 All Movies
%table#movies
%thead
%tr
%th= link_to 'Movie Title', new_movie_path
%th Rating
%th Release Date
%th More Info
%tbody
- @movies.each do |movie|
%tr
%td= movie.title
%td= movie.rating
%td= movie.release_date
%td= link_to "More about #{movie.title}", movie_path(movie)
= link_to 'Add new movie', new_movie_path
根据作业,我应该编辑索引,以便将“所有电影”按顺序排列。我查找了 ruby 的排序方法,它是 movie.order()。我不知道在括号里放什么。
class MoviesController < ApplicationController
def show
id = params[:id] # retrieve movie ID from URI route
@movie = Movie.find(id) # look up movie by unique ID
# will render app/views/movies/show.<extension> by default
end
def index
@movies = Movie.order(id)
end
def new
# default: render 'new' template
end
def create
@movie = Movie.create!(params[:movie])
flash[:notice] = "#{@movie.title} was successfully created."
redirect_to movies_path
end
def edit
@movie = Movie.find params[:id]
end
def update
@movie = Movie.find params[:id]
@movie.update_attributes!(params[:movie])
flash[:notice] = "#{@movie.title} was successfully updated."
redirect_to movie_path(@movie)
end
def destroy
@movie = Movie.find(params[:id])
@movie.destroy
flash[:notice] = "Movie '#{@movie.title}' deleted."
redirect_to movies_path
end
end
所以根本问题,我不知道如何正确编辑方法索引以给出我的“电影”目录顺序,也不知道如何将标题电影标题分配给索引。