Reputation: 1684
Im using twitter bootstrap for design. I want to use a different template for a specific action
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
As soon as i add in the render layout to the action I get this error message
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>
If I take the render away the page will load just fine.
Upvotes: 1
Views: 428
Reputation: 17735
You're rendering too early. Try this:
format.html { render :layout => 'single' }
Or for a more scalable method, see this question and answer.
Upvotes: 2
Reputation: 1321
Don't call render
in the beginning of your view
method. Call it in the end.
upd:
Oh.. In your case you should call it in format.html { render ... }
. Sorry.
Upvotes: 0