如何在视图中显示最新内容

时间:2013-09-19 19:36:41

标签: ruby-on-rails

我的问题表包含以下列:id,question,answer,created_at,updated_at,sender_id,recipient_id。

最新问题应该出现在最上面。

问题主持人:

 def index
    @questions = Question.all
    respond_with(@questions)
end

def show
  @question = Question.find(params[:id])
  respond_with(@questions)
end

答案控制器:

  def new
    @question = Question.find(params[:question_id])
  end

  def create
    @question = Question.find(params[:question_id])
    if @question.update_attributes(params[:question])
      redirect_to questions_path
    else
      render :new
    end

路线:

  resources :questions do
    resources :answers, only: [:new, :create]
  end

1 个答案:

答案 0 :(得分:1)

@questions = Question.order("created_at DESC")