title: Couldn't find User with id= (ActiveRecord::RecordNotFound)
body: <p>With my rails app I can successfully create an object (called work; think of them as blog posts) as current_user. A user has_many works. I can validate that the object is created successfully by checking the database using my postgresql browser. The table also holds the correct user_id that created the work so I know that my create function works in my controller.</p>
  
  <p>However, the problem is that when I try to view the work, I get the following error:</p>
  
  <p>ActiveRecord::RecordNotFound in WorksController#show</p>
  
  <p>Couldn't find User with id=23</p>
  
  <p>app/controllers/works_controller.rb:43:in `show'</p>
  
  <p>What's odd is that I can still view works that I created several weeks ago. The error only appears for works that I have created recently.</p>
  
  <p>Here's the Works controller:</p>
  
  <pre><code>class WorksController &lt; ApplicationController
     #before_filter :current_user,   only: [:edit, :update]
  
    def index
      @works = Work.all
  
  respond_to do |format|
    format.html # index.html.erb
    format.xml  { render :xml =&gt; @works }
  end
  end
  def create
      @work = current_user.works.create(params[:work])
      redirect_to current_user
    end
  
  def edit
      @work = current_user.works.find(params[:id])
  end
  
  def new
    @work = current_user.works.new
  end
  
  def destroy
    @work = current_user.works.find(params[:id]).destroy
    flash[:success] = "Work deleted"
    redirect_to current_user
  end
  
   def update
      @work = current_user.works.find(params[:id])
      if @work.update_attributes(params[:work])
        flash[:success] = "updated"
        redirect_to @work
      else
        render 'edit'
      end
    end
  
  
    def show
      @user = User.find(params[:id])
      @work = @user.works.find(params[:id])
      @activities = PublicActivity::Activity.order("created_at DESC").where(trackable_type: "Work", trackable_id: @work).all
  
      respond_to do |format|
        format.html # show.html.erb
        format.xml  { render :xml =&gt; @work }
      end
    end
  end
  </code></pre>
  
  <p>I'm assuming the error is in the Works controller. What do I need to edit in the controller in order to fix the "show" errors?</p>
  
  <p>EDIT: If I use the current code above, I can only view other people's works (viewing my own throws an error). However, if I add current_user into the query (such as @works= current_user.works), I can then only see my own works. Viewing other people's works throws an error. How can I fix this so that I can view both my own works and works created by others?</p>
  
  <p>EDIT 2:</p>
  
  <p>@work = Work.find(params[:id]) works if I remove @user from the controller and the "@user" references in the works show.html view file. However, I need the "@user" reference in the controller because I want to display the name of the user that created the work. How should I go about doing this? </p>
  
  <p>EDIT 3:</p>
  
  <p><strong>FIXED! Thanks again to everyone who contributed their answers! Here's what I did to fix it:</strong></p>
  
  <ol>
  <li><p>I removed the @user reference from the controller ("show" action). As Fred mentioned below the @user reference is not needed and needed to be removed since I was using :id twice to reference two separate objects. </p></li>
  <li><p>Edited the "@work" variable to <code>@work = Work.find(params[:id])</code>. This will look for the correct work item based on the id regardless of which user created it.</p></li>
  <li><p>When I need to display the user data on the work pages, simply use <code>&lt;%= @work.user.name %&gt;</code> on the show.html.erb view page. '@user = User.find(params[:id])' is not needed since I already defined a foreign key relationship on the works model by using 'belongs_to :user'.</p></li>
  </ol>
  
  <p>Thanks again for all of the help!
  -j</p>