2012-04-15 95 views
1

Im使用twitter bootstrap设计。我想,只要我在渲染布局添加到操作我收到此错误信息Rails 3渲染布局在行动导致错误与Twitter Bootstrap

undefined method `model_name' for NilClass:Class 

Extracted source (around line #2): 

1: <%- model_class = @movie.class -%> 
2: <h1><%=t '.title', :default => model_class.model_name.human %></h1> 
3: 
4: <p> 
5: <strong><%= model_class.human_attribute_name(:title) %>:</strong><br> 

如果我把渲染离开该页面使用不同的模板的具体行动

def view 
    render :layout => 'single' 
    @movie = Movie.find(params[:id]) 
    respond_to do |format| 
    format.html # show.html.erb 
    format.json { render json: @movie } 
end 
end 

将加载得很好。

回答

2

您渲染得太早。试试这个:

format.html { render :layout => 'single' } 

或者对于更具扩展性的方法,请参阅this question and answer

0

不要在view方法的开头调用render。最后调用它。

更新: 哦..在你的情况下,你应该叫它format.html { render ... }。抱歉。