I have a rails app that uses partials and in development everything works great but in production I am getting the error
We’re sorry, but something went wrong.
We’ve been notified about this issue and we’ll take a look at it shortly.
I checked my production.log file and this is the error I am receiving
ActionView::Template::Error (undefined method `model_name’ for NilClass:Class):
Here is the lines that are causing the problems
<%= div_for blog do %>
and here is whats causing that file
<%= render :partial => 'blogs/blog', :locals => {:blog => @profile.blogs.last}%>
here’s the entire error
ActionView::Template::Error (undefined method `model_name' for NilClass:Class):
1: <%= div_for blog do %>
2: <p>
3: <b>Title:</b>
4: <%= blog.title %>
app/views/blogs/_blog.html.erb:1:in
app/views/profiles/show.html.erb:22:in
any ideas on how I can resolve this error?
You are effectively calling
nil.lastwhich will throw this kind of error.Use a conditional to render the partial only if
@profilecontains blogs:Or, what I would do, use a partial. In your view:
In a partial: