← Back to Upcase

Intermediate Rails: undefined method `shouts' for Dashboard


(Jean) #1

Working my way through video three of Intermediate Rails, and I cannot for the life of me understand why I’m getting this error when I refresh my dashboards#show page.

My controller looks like this, as per the refactor:

 class DashboardsController < ApplicationController                                    
   def show                                                                            
     @dashboard = Dashboard.new(current_user)                                          
   end
 end  

And my dashboard model looks like this:

   class Dashboard
    #removed additional working code for brevity
    def shouts
      @user.shouts
    end
  end

My dashboards#show page includes this line, which is throwing the error:

<%= render @dashboard.shouts %>

I’ve tried playing with this in the console, and if I create a user that has some shouts, then create a new dashboard with that user and call dashboard.shouts, I just keep getting an undefined method shouts for dashbaord error.

I can’t see what’s going wrong, so any insight would be appreciated.

Thank you!


(Andy Waite) #2

It looks correct to me. Could you push your repo up GitHub repo so I can see the full thing?


(Nikola Novakovic) #3

Ultimately you’re gonna have to push this to some repo somewhere so we have a broader picture of the code and can help you out with more details, but for now here are some questions to ask yourself:

Are you sure you have access to correct things inside of Dashboard class ? What does your initialize gets as params ?


(Jean) #4

So, I previously had worked through this video and was having trouble with this video in particular. I branched from my completed project and reverted back to the last commit I had made before the start of video three. I thought it had rolled back everything, but from what I can tell, it didn’t remove the app/models/timeline.rb file, which was confusing things. I deleted the file and it seems to work just fine now.