在查看 haml 文件中,我有一个链接,当您单击时,您将获得按标题或发行日期排序的所有电影。控制器中的代码是:
def index
sort = params[:sort] || session[:sort]
case sort
when 'title'
ordering,@title_header = {:order => :title}, 'hilite'
when 'release_date'
ordering,@date_header = {:order => :release_date}, 'hilite'
end
# some more codes here
@movies = Movie.find_all_by_rating(@selected_ratings.keys, ordering)
end
如果我改变
ordering,@title_header = {:order => :title}, 'hilite'
至
ordering,@title_header = {:order => title}, 'hilite'
它给出了一个错误:
undefined local variable or method `title' for #<MoviesController:0xb29a853c>