title: Routing nested resources and matching controller
body: <p>I've had a problem over the last few days getting my nested resources to create and display properly.  There are tons of similar questions on StackOverflow and lots of blog posts on this, but they all seem to either deal with a older version of Rails or a different issue.  I'm at the point where once I finally fix something, another error pops up. I've narrowed it down to me making a stupid mistake or typo being too inexperienced to notice.</p>
  
  <p>I have a Jobs model that belongs to a Venue model.  The venue works fine and I've even gotten as far as to be able to go to my nested Jobs index under each Venue and bring up the New and Edit forms, but going to 'Show' or creating a new Job caused an <code>undefined method</code> error.  After a lot of searching I found plenty with the same problem and tried to implement their fixes, but now I'm getting a Routing Error.</p>
  
  <p>Most of my confusing comes from when to leave off the @, when to use :venue_id instead of :id in params, etc.  Every example I see seems to have a different way and I can't seem to make any of them work for me.</p>
  
  <p>Any bump in the right direction would be extremely helpful.</p>
  
  <p><strong>The Routing Error</strong></p>
  
  <pre><code>No route matches {:action=&gt;"show", :controller=&gt;"jobs", :venue_id=&gt;#&lt;Venue id: 1, name: "Burger Chef", city: "Chicago", state: "Illinois", areacode: 60614, created_at: "2013-02-05 21:33:41", updated_at: "2013-02-06 23:01:05", avatar_file_name: nil, avatar_content_type: nil, avatar_file_size: nil, avatar_updated_at: nil&gt;}
  </code></pre>
  
  <p><strong>routes.rb</strong></p>
  
  <pre><code>Twist::Application.routes.draw do
  
  
    resources :users
    devise_for :users
  
    resources :venues do
      resources :jobs
    end
  
  end
  </code></pre>
  
  <p><strong>jobs_controller.rb</strong></p>
  
  <pre><code>class JobsController &lt; ApplicationController
    # GET /jobs
    # GET /jobs.json
    before_filter :get_venue
  
    def get_venue
      @venue = Venue.find(params[:venue_id])
    end
  
    def index
      @jobs = @venue.jobs
  
      respond_to do |format|
        format.html # index.html.erb
        format.json { render json: @jobs }
      end
    end
  
    # GET /jobs/1
    # GET /jobs/1.json
    def show
      @job = @venue.job.find(params[:id])
  
      if params[:id]
        @venue = Venue.where(:id =&gt; params[:id]).first
        @jobs = @venue.job_url
      else
        @jobs = Jobs.all
      end
  
      respond_to do |format|
        format.html # show.html.erb
        format.json { render json: @job }
      end
    end
  
    # GET /jobs/new
    # GET /jobs/new.json
    def new
      @job = @venue.jobs.build
  
      respond_to do |format|
        format.html # new.html.erb
        format.json { render json: @job }
      end
    end
  
    # GET /jobs/1/edit
    def edit
      @job = @venue.job.find(params[:venue_id])
  
  
    end
  
    # POST /jobs
    # POST /jobs.json
    def create
      @job = @venue.jobs.new(params[:job])
  
      respond_to do |format|
        if @job.save
  
  
          format.html { redirect_to :action =&gt; :show, :id =&gt; @venue.id, 
                        notice: 'Job was successfully created.' }
          format.json { render json: [@venue, @job],
                               status: :created, 
                               location: [@venue, @job] }
        else
          format.html { render action: "new" }
          format.json { render json: @job.errors, status: :unprocessable_entity }
        end
      end
    end
  
    # PUT /jobs/1
    # PUT /jobs/1.json
    def update
      @job = Job.find(params[:id])
  
      respond_to do |format|
        if @job.update_attributes(params[:job])
          format.html { redirect_to @job, notice: 'Job was successfully updated.' }
          format.json { head :no_content }
        else
          format.html { render action: "edit" }
          format.json { render json: @job.errors, status: :unprocessable_entity }
        end
      end
    end
  
    # DELETE /jobs/1
    # DELETE /jobs/1.json
    def destroy
      @job = Job.find(params[:id])
      @job.destroy
  
      respond_to do |format|
        format.html { redirect_to jobs_url }
        format.json { head :no_content }
      end
    end
  end
  </code></pre>
  
  <p><strong>venues_controller.rb</strong></p>
  
  <pre><code>class VenuesController &lt; ApplicationController
    # GET /venues
    # GET /venues.json
  
  
    def index
      @venues = Venue.all
  
      if params[:name]
        @user = User.where(:name =&gt; params[:name]).first
        @venues = @user.venues
      end
  
      respond_to do |format|
        format.html # index.html.erb
        format.json { render json: @venues }
      end
    end
  
    # GET /venues/1
    # GET /venues/1.json
    def show
      @venue = Venue.find(params[:id])
  
  
      respond_to do |format|
        format.html # show.html.erb
        format.json { render json: @venue }
      end
    end
  
    # GET /venues/new
    # GET /venues/new.json
    def new
      @venue = Venue.new
  
      respond_to do |format|
        format.html # new.html.erb
        format.json { render json: @venue }
      end
    end
  
    # GET /venues/1/edit
    def edit
      @venue = Venue.find(params[:id])
  
      #if session[:user_id] != @venue.user_id
      #  flash[:notice] = "Sorry, you cannot edit this venue."
      #  redirect_to(venues_path)
      # =&gt;end
    end
  
    # POST /venues
    # POST /venues.json
    def create
      @venue = Venue.new(params[:venue_id])
  
  
      respond_to do |format|
        if @venue.save
          format.html { redirect_to @venue, notice: 'Venue was successfully created.' }
          format.json { render json: @venue, status: :created, location: @venue }
        else
          format.html { render action: "new" }
          format.json { render json: @venue.errors, status: :unprocessable_entity }
        end
      end
    end
  
    # PUT /venues/1
    # PUT /venues/1.json
    def update
      @venue = Venue.find(params[:id])
  
      respond_to do |format|
        if @venue.update_attributes(params[:venue])
          format.html { redirect_to @venue, notice: 'Venue was successfully updated.' }
          format.json { head :no_content }
        else
          format.html { render action: "edit" }
          format.json { render json: @venue.errors, status: :unprocessable_entity }
        end
      end
    end
  
    # DELETE /venues/1
    # DELETE /venues/1.json
    def destroy
      @venue = Venue.find(params[:id])
      @venue.destroy
  
      respond_to do |format|
        format.html { redirect_to venues_url }
        format.json { head :no_content }
      end
    end
  end
  </code></pre>
  
  <p><strong>job.rb</strong></p>
  
  <pre><code>class Job &lt; ActiveRecord::Base
    attr_accessible :description, :name, :requirement, :venue_id
  
    validates :name, :presence =&gt; true, :length =&gt; { :minimum =&gt; 3 }
  
    belongs_to :venue
  end
  </code></pre>
  
  <p><strong>venue.rb</strong></p>
  
  <pre><code>class Venue &lt; ActiveRecord::Base
    attr_accessible :areacode, :avatar, :city, :name, :state
  
  
    has_many :jobs
  
    has_attached_file :avatar, :styles =&gt; { :medium =&gt; "300x300&gt;", :thumb =&gt; "100x100&gt;" }
  
  end
  </code></pre>
  
  <p><strong>/jobs/show.html.erb</strong></p>
  
  <pre><code>&lt;p id="notice"&gt;&lt;%= notice %&gt;&lt;/p&gt;
  
  
      &lt;% @job = Job.find(param[:venue_id]) %&gt;
  
      &lt;p&gt;
        &lt;b&gt;Name:&lt;/b&gt;
        &lt;%= @job.name %&gt;
      &lt;/p&gt;
  
      &lt;p&gt;
        &lt;b&gt;Company:&lt;/b&gt;
        &lt;p&gt;&lt;%= @venue.name %&gt;&lt;/p&gt;
        &lt;p&gt;&lt;%= link_to @job.venue.name, venue_path(@venue) %&gt;&lt;/p&gt;
  
  
      &lt;p&gt;
        &lt;b&gt;Job:&lt;/b&gt;
        &lt;%= @job.job_id %&gt;
      &lt;/p&gt;
  
      &lt;p&gt;
        &lt;b&gt;Description:&lt;/b&gt;
        &lt;%= @job.description %&gt;
      &lt;/p&gt;
  
      &lt;p&gt;
        &lt;b&gt;Requirement:&lt;/b&gt;
        &lt;%= @job.requirement %&gt;
      &lt;/p&gt;
  
  
  
  
      &lt;%= link_to 'Edit', edit_venue_job_path(@venue, @job) %&gt; |
      &lt;%= link_to 'Back', venue_jobs_path(@venue, @job) %&gt;
  
  **/jobs/index.html.erb**
  
  &lt;div class="usergrid"&gt;
  
    &lt;% jobs = @venue.jobs %&gt;
  
  
    &lt;% @venue.jobs.each do |job| %&gt;
  &lt;div class = "user venue"&gt;
  
      &lt;p&gt;
          &lt;h2&gt;&lt;%= link_to job.name, venue_job_path(@venue) %&gt;&lt;/h2&gt;
          &lt;%= link_to 'Edit', edit_venue_job_path(@venue, job) %&gt;&lt;br/&gt;
          &lt;%= link_to 'Delete', venue_jobs_path(@venue, @job), :confirm =&gt; 'Are you sure?', :method =&gt; :delete %&gt;
  &lt;/div&gt;
  &lt;% end %&gt;
  &lt;div style="clear:both"&gt;&lt;/div&gt;
  &lt;/div&gt;
  
  
  
  
  &lt;%= link_to 'New Job', new_venue_job_path(@venue) %&gt;
  </code></pre>
  
  <p>I realize that...</p>
  
  <ol>
  <li>This might be a really obvious fix, but being new to Rails there are definitely still some fundamentals that I don't completely understand.</li>
  <li>If I posted too much or too little code please let me know, I'm not entirely sure how much is the least necessary for this.</li>
  <li>There might be more than one error, there might be a lot of errors, and many of them could have been caused by me trying to fix this when I really didn't know what I was doing.  I wanted to fix this myself, but I can't handle messing with it anymore when I'm really just making it worse.</li>
  </ol>
  
  <p>I've tried messing with the routes, changing the actual links and routes, messing with scope, and as many of the common fixes for these errors that I could find and none of them seemed to help.</p>
  
  <p>Thanks!</p>