2

ruby 有没有办法绕过 application.html.erb 但仍然使用控制器的相应视图?

现在我有

render :layout => false

但我从视图中得到以下错误:

undefined method `each' for nil:NilClass

以下是我当前的帖子控制器:

class PostsController < ApplicationController
  def index
    @posts = Post.where('is_deleted' => false, 'is_hidden' => false).limit(15).order('created_at DESC')
  end 
  def show
    @posts = Post.find(params[:id], :conditions => 'is_deleted = false')
  end 
  def page
    render :layout => false
    @posts = Post.where('is_deleted' => false, 'is_hidden' => false).limit(15).offset(params[:page].to_i * 15).order('created_at DESC')
  end 
end
4

1 回答 1

4
def page
  render :layout => false
  @posts = Post.where('is_deleted' => false, 'is_hidden' => false).limit(15).offset(params[:page].to_i * 15).order('created_at DESC')
 end 

应该

def page
  @posts = Post.where('is_deleted' => false, 'is_hidden' => false).limit(15).offset(params[:page].to_i * 15).order('created_at DESC')
  render :layout => false
end
于 2012-12-03T02:33:32.427 回答