title: Error 404 when uploading a file caused by error in update function
body: <p>I'm having a hard time trying to figure out what's wrong in my code. Basically, I'm using <code>Dropzone-js's</code> file uploader, that uses drag and drop.  I can't upload a file because it returns me a <code>404 error</code>.
  I searched through my logs and found that I had a problem in my <code>controller</code>, in the <code>update</code> function.</p>
  
  <p><strong>The controller</strong> :</p>
  
  <pre><code>class ChatRoomsController &lt; ApplicationController
  before_action :authenticate_user!
  before_action :set_room, only: [:index, :new, :create, :show, :edit, :signal]
  before_action :set_participant, only: [:signal]
  
  def index
    @chat_rooms = ChatRoom.all
  end
  
  def show
    # Show room messages
    @chat_room = ChatRoom.includes(:messages).find_by(id: params[:id])
    @message = Message.new
  
    @chat_room.participant?(current_user)
  
    # TODO: get participant only once
    if params[:guid]
      if @participant = User.find(params[:guid])
        @participant.joined_at = Time.now
        @chat_room.add_to_call(@participant)
      end
    elsif params[:del]
      if @participant = User.find(params[:del])
        @chat_room.remove_from_call(@participant)
      end
    end
  
    response = {
        room: @chat_room,
        # Get all call participants
        users: @chat_room.call_users,
        signals: deliver_signals!
    }
  
    respond_to do |format|
      format.html
      format.json { render json: response }
    end
  
  end
  
  def new
    @chat_room = ChatRoom.new
  end
  
  def edit
    # Empty
  end
  
  def create
    @chat_room = current_user.chat_rooms.build(chat_room_params)
    if @chat_room.save
      @group_room.users &lt;&lt; current_user
      redirect_to chat_rooms_path
    else
      render 'new'
    end
  end
  
  def update
    @chat_room = ChatRoom.find(id: params[:chat_room_id])
    if @chat_room.update_resource(chat_room_params)
      flash[:success] = 'test'
    else
      render 'edit'
    end
  end
  
  def signal
    signal = signal_params
    signal[:chat_room] = @chat_room
    signal[:sender] = User.find(signal[:sender])
    signal[:recipient] = @participant
    logger.info('Signal is ' + signal.to_param)
    ChatRoomSignal.create! signal
    head 204
  end
  
  def deliver_signals!
    data = ChatRoomSignal.where recipient: @participant
  
    # Destroy the signals as we return them, since they have been delivered
    result = []
    data.each do |signal|
      result &lt;&lt; {
          signal_type: signal.signal_type,
          sender_guid: signal.sender_id,
          recipient_guid: signal.recipient_id,
          data: signal.data,
          chat_room_id: signal.chat_room_id,
          timestamp: signal.created_at
      }
    end
    data.delete_all
    result
  end
  
  private
  
  def set_participant
    @participant = User.find(params[:user_id])
  rescue ActiveRecord::RecordNotFound
    # Retry with ID as GUID
    @participant = User.where(id: params[:user_id]).first
    raise unless @participant
  end
  
  def set_room
    @chat_room = ChatRoom.includes(:messages).find_by(id: params[:chat_room_id])
  end
  
  def chat_room_params
    params.require(:chat_room).permit(:title, :image)
  end
  
  def signal_params
    params.permit(:sender, :signal_type, :data)
  end
  </code></pre>
  
  <p><strong>HTML code for file upload</strong> :</p>
  
  <pre><code>&lt;div class="panel-body"&gt;
    &lt;%= form_for @chat_room, html: { multipart: true, class: "dropzone", id: "my-dropzone"} do |f| %&gt;
  
      &lt;div class="dz-message needsclick"&gt;
        &lt;h3&gt;Drop a file here&lt;/h3&gt; or &lt;strong&gt;click&lt;/strong&gt; to upload
      &lt;/div&gt;
  
      &lt;div class="fallback"&gt;
        &lt;% f.file_field :image, as: :file %&gt;
        &lt;%= f.submit "Upload your file" %&gt;
      &lt;/div&gt;
   &lt;% end %&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p><strong>The error :</strong></p>
  
  <pre><code>[ActionCable] [test@test.com] ChatRoomsChannel is transmitting the subscription confirmation
  [ActionCable] [test@test.com] ChatRoomsChannel is streaming from chat_rooms_1_channel
  Started PATCH "/chat_rooms/1" for 127.0.0.1 at 2017-06-09 01:44:26 +0200
  Processing by ChatRoomsController#update as JSON
  Parameters: {"utf8"=&gt;"✓", "authenticity_token"=&gt;"p8KEWBx7fmJmEhHgINmp5rnj+PVwGXfbPHxslSaA4Z/5zA6HIJzxeBjwcz/+GcDEQKKwPwjXNJVnBtfq7xu2qw==", "chat_rooms"=&gt;{"image"=&gt;#    &lt;ActionDispatch::Http::UploadedFile:0x007f640e58f5b0 @tempfile=#&lt;Tempfile:/tmp/RackMultipart20170609-2887-1nuat54.png&gt;, @original_filename="Screenshot from 2017-04-12 12-47-21.png", @content_type="image/png", @headers="Content-Disposition: form-data; name=\"chat_rooms[image]\"; filename=\"Screenshot from 2017-04-12 12-47-21.png\"\r\nContent-Type: image/png\r\n"&gt;}, "id"=&gt;"1"}
    [1m[36mUser Load (0.2ms)[0m  [1m[34mSELECT  "users".* FROM "users" WHERE "users"."id" = ? ORDER BY "users"."id" ASC LIMIT ?[0m  [["id", 1], ["LIMIT", 1]]
    [1m[36mChatRoom Load (0.2ms)[0m  [1m[34mSELECT  "chat_rooms".* FROM "chat_rooms" WHERE "chat_rooms"."id" = ? LIMIT ?[0m  [["id", nil], ["LIMIT", 1]]
  Completed 404 Not Found in 7ms (ActiveRecord: 0.3ms)
  
  
  
  ActiveRecord::RecordNotFound (Couldn't find ChatRoom with 'id'={:id=&gt;nil}):
  
  app/controllers/chat_rooms_controller.rb:62:in `update'
  </code></pre>
  
  <p><strong>Line 62</strong> :</p>
  
  <pre><code>@chat_room = ChatRoom.find(id: params[:chat_room_id])
  </code></pre>
  
  <p>So it seems like my <code>controller</code> is not able to find the <code>id</code> parameter, but i don't understand why. And this is probably the error that causes my file to return <code>404 error</code>.</p>
  
  <p>Thanks for the time you will take to read my post.</p>