title: Ruby on Rails: Getting Params from URL
body: <p>On Rails 4, I am having trouble getting the params from a URL in my controller.</p>
  
  <p>I have two models with a has_many and belongs_to association, let's call them Books and Pages. I want to create a new Page record and have it link to the Book model depending on which book the user was visiting when they clicked on the "Create" button (i.e. if a user was on the Jurassic Park book page and clicked "Create," I want to create a new page that is associated with the Jurassic Park book).</p>
  
  <p>Here is the create link from my view:</p>
  
  <pre><code>&lt;%= link_to "Create page", new_page_path(:book =&gt; @book.id), :id =&gt; "submit-button" %&gt;
  </code></pre>
  
  <p>Here is my controller:</p>
  
  <pre><code>def new
    @page = Page.new
  end
  
  def create
    @book = Book.find(params[:book])
    @page = Product.new(page_params)
    @page.book_id = @book.id
    if @page.save
      flash[:success] = "Page Submitted!"
      redirect_to @book
    else
      render 'new'
    end
  end
  </code></pre>
  
  <p>I get the following error: </p>
  
  <blockquote>
    <p>"ActiveRecord::RecordNotFound in PagesController#create - Couldn't
    find Book without an ID"</p>
  </blockquote>
  
  <p>Am I doing this completely wrong? I know Rails 4 changed the way params work which is the same syntax as getting the URL parameters, so perhaps that is what is causing this issue.</p>
  
  <p>Edit: I also tried getting the params from 'new' as a variable and then using that as the id, but I get the same error message.</p>