title: Can't read parameter in controller, Ruby on Rails
body: <p>In my Ruby on Rails project, I want, depending on which link you click, that the resulting created object has a different number.</p>
  
  <p>I have a book and a chapter model, chapter belongs to book. Chapter has an integer attribute called "place". </p>
  
  <p>At the moment, when I click on the link: <code>http://localhost:3000/1/chapters/new/</code>
  It renders the new.html.erb page and everything works fine.</p>
  
  <p>Now, I added a new route:</p>
  
  <pre><code>chapterchapter GET    /:book_id/chapters/new(.:format)/:place     chapters#new
  </code></pre>
  
  <p>This link</p>
  
  <pre><code>&lt;%= link_to "Contribute", chapterchapter_path(@book, 5 ) %&gt;
  </code></pre>
  
  <p>will result in:</p>
  
  <pre><code>http://localhost:3000/1/chapters/new/5
  </code></pre>
  
  <p>In my controller, I have this line of code:</p>
  
  <pre><code>  def new
      @chapter = Chapter.new
    end
  
    def create
      @chapter = Chapter.new(chapter_params)
      @chapter.book_id = @book.id
      @chapter.user_id = current_user.id
      @chapter.place = params[:place]
  </code></pre>
  
  <p>My problem is, this line of code: <code>@chapter.place = params[:place]</code>does not work, since the created chapter returns nil for chapter.place. What do I need to do, that @chapter.place reads the parameter :place? Any advices?</p>
  
  <p>Edit: My database schema:</p>
  
  <pre><code>ActiveRecord::Schema.define(version: 20160117110001) do
  
    create_table "books", force: :cascade do |t|
      t.string   "title"
      t.text     "description"
      t.integer  "maxnumchapt"
      t.datetime "created_at",  null: false
      t.datetime "updated_at",  null: false
      t.integer  "min_length"
      t.integer  "max_length"
      t.integer  "user_id"
    end
  
    create_table "chapters", force: :cascade do |t|
      t.string   "chaptertitle"
      t.text     "chaptercontent"
      t.string   "author"
      t.datetime "created_at",     null: false
      t.datetime "updated_at",     null: false
      t.integer  "book_id"
      t.integer  "user_id"
      t.integer  "place"
    end
  
    create_table "users", force: :cascade do |t|
      t.string   "email",                  default: "", null: false
      t.string   "encrypted_password",     default: "", null: false
      t.string   "reset_password_token"
      t.datetime "reset_password_sent_at"
      t.datetime "remember_created_at"
      t.integer  "sign_in_count",          default: 0,  null: false
      t.datetime "current_sign_in_at"
      t.datetime "last_sign_in_at"
      t.string   "current_sign_in_ip"
      t.string   "last_sign_in_ip"
      t.datetime "created_at",                          null: false
      t.datetime "updated_at",                          null: false
    end
  
    add_index "users", ["email"], name: "index_users_on_email", unique: true
    add_index "users", ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
  
  end
  </code></pre>
  
  <p>Edit 2: It seems, as soon as I press the submit button, the parameter place gets lost:</p>
  
  <pre><code>Started GET "/30/chapters/new/2" for 127.0.0.1 at 2016-01-17 23:39:07 +0100
  Processing by ChaptersController#new as HTML
    Parameters: {"book_id"=&gt;"30", "place"=&gt;"2"}
    Book Load (0.1ms)  SELECT  "books".* FROM "books" WHERE "books"."id" = ? LIMIT 1  [["id", 30]]
    Rendered chapters/new.html.erb within layouts/application (36.8ms)
    User Load (0.1ms)  SELECT  "users".* FROM "users" WHERE "users"."id" = ?  ORDER BY "users"."id" ASC LIMIT 1  [["id", 1]]
  Completed 200 OK in 55ms (Views: 53.2ms | ActiveRecord: 0.2ms)
  
  
  Started POST "/books/30/chapters" for 127.0.0.1 at 2016-01-17 23:39:16 +0100
  Processing by ChaptersController#create as HTML
    Parameters: {"utf8"=&gt;"✓", "authenticity_token"=&gt;"566kl+qg5otw1FGVh0uIoytGxFlF5qp0c4Ws41JhtzSzhqWuND997PltE7LXGiIvEC7A/uqCtg8WMdnNndN/Rg==", "chapter"=&gt;{"chaptertitle"=&gt;"fadfadfaf", "chaptercontent"=&gt;"afddfaf", "author"=&gt;"adfadfa"}, "commit"=&gt;"Create Chapter", "book_id"=&gt;"30"}
    Book Load (0.1ms)  SELECT  "books".* FROM "books" WHERE "books"."id" = ? LIMIT 1  [["id", 30]]
    User Load (0.1ms)  SELECT  "users".* FROM "users" WHERE "users"."id" = ?  ORDER BY "users"."id" ASC LIMIT 1  [["id", 1]]
  </code></pre>
  
  <p>Edit 3: Chapters/new.html</p>
  
  <pre><code>&lt;%= simple_form_for([@book, @book.chapters.build]) do |f| %&gt;
      &lt;%= f.input :chaptertitle %&gt;
      Mininmum amount of characters: &lt;%= @book.min_length %&gt; Maximum amount of characters: &lt;%= @book.max_length %&gt;
      &lt;div class="counting" &gt;&lt;%= f.input :chaptercontent %&gt;Characters: &lt;span class="count"&gt;&lt;/span&gt;&lt;/div&gt;&lt;br&gt;
      &lt;%= f.input :author %&gt;
      &lt;%= f.button :submit %&gt;
  &lt;% end %&gt;
  
  &lt;script&gt;
  
    $(document).ready(function(){
  
      var choosingbar = function( event ){
        $(event.target).parents(".counting").children(".count").text($(event.target).val().length);
      };
  
      $(".counting textarea").keyup(choosingbar);
    });
  
  &lt;/script&gt;
  </code></pre>