title: Why do I get a 500 error (undefined method 'to_model' on save of duplicated Ruby on Rails Model
body: <p>I'm new to rails and still fuzzy on some things but here goes.</p>
  
  <p>I am sending json post request to /microposts/10/duplicate.json to duplicate a micropost.</p>
  
  <p>The route goes to microposts#duplicate</p>
  
  <p>The Controller action is:</p>
  
  <pre><code>def duplicate
    micropost = current_user.microposts.find(params[:id])
    new_micropost = micropost.dup
    respond_with new_micropost.save
  end
  </code></pre>
  
  <p>The server logs for the request is:</p>
  
  <pre><code>Started POST "/microposts/15/duplicate.json" for 180.181.247.76 at 2015-09-06 11:00:38 +0000
  Processing by MicropostsController#duplicate as JSON
    Parameters: {"_json"=&gt;15, "id"=&gt;"15", "micropost"=&gt;{}}
    User Load (0.3ms)  SELECT  "users".* FROM "users" WHERE "users"."id" = ? LIMIT 1  [["id", 2]]
    Micropost Load (0.3ms)  SELECT  "microposts".* FROM "microposts" WHERE "microposts"."user_id" = ? AND "microposts"."id" = ?  ORDER BY "microposts"."created_at" DESC LIMIT 1  [["user_id", 2], ["id", 15]]
     (0.1ms)  begin transaction
    SQL (0.4ms)  INSERT INTO "microposts" ("content", "user_id", "title", "link", "created_at", "updated_at") VALUES (?, ?, ?, ?, ?, ?)  [["content", "RLCPYIIG"], ["user_id", 2], ["title", "herp"], ["link", "snerp"], ["created_at", "2015-09-06 11:00:38.576553"], ["updated_at", "2015-09-06 11:00:38.576553"]]
     (11.7ms)  commit transaction
  Completed 500 Internal Server Error in 28ms (ActiveRecord: 12.8ms)
  
  NoMethodError (undefined method `to_model' for true:TrueClass):
    app/controllers/microposts_controller.rb:23:in `duplicate'
  </code></pre>
  
  <p>So the micropost is saved but I don't know why I get the 500 error.
  Also, should I be using .require and .permit here? The only thing in params from the front end should be the id.</p>
  
  <p>Any help would be appreciated.</p>