On 18 November 2012 15:29, Dave Castellano <[email protected]> wrote: > I am trying to render a file from Subject resource in a User resource > view. I am getting error: > undefined method `each' for nil:NilClass. Apparently @subject is nil > but not sure how to fix this... > > Here is User resourve view (users/show.html.erb) > <%= render 'subjects/index' %>
Are you just trying to go to that page? If so then use redirect_to rather than render, this will go to the subjects#index action on subjects and then render it as normal. As you have it you are trying to render the view without calling the action, so @subjects is not set up. If you are trying to do something other than just going to that page then please explain in more detail. Colin > > Here is subjects_controller > def show > @subject = Subject.find(params[:id]) > ... > end > > Here is subjects/index.html.erb (The file I want to render) > <% @subjects.each do |subject| %> > <tr> > <td class="hilite_list"> > <a href="/books/index_books/<%= subject.id %>"><%= > subject.title %> (<%= subject.questions.count %>)</a> > </td> > > -- > Posted via http://www.ruby-forum.com/. > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit https://groups.google.com/groups/opt_out. > > -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit https://groups.google.com/groups/opt_out.

