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
答案 0 :(得分: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