Beim Erstellen eines neuen Datensatzes wird die falsche Benutzer-ID gespeichert

Habe gerade Hilfe bekommen, habe aber jetzt ein neues Problem ... Ich versuche, alle "Commits" (dies sind im Grunde genommen einfache Bearbeitungen) für ein bestimmtes Projekt aufzulisten. Dies funktioniert derzeit, aber wenn ich versuche, den Benutzer aufzulisten, der das Commit erstellt hat, wird das falsche Benutzerprofilbild (oder der falsche Name usw.) angezeigt. Was passiert ist, dass die Person, die das Projekt erstellt hat, derzeit auch die user_id für alle Commits ist.

Benutzer A erstellt das Projekt ... dann kommt Benutzer B und fügt ein Commit hinzu. Aber es wird aus irgendeinem Grund Benutzer A als Profilbild für ALL angezeigt, und ich kann nicht genau herausfinden, warum. Dies muss etwas mit den Methoden 'new' oder 'create' für Festschreibungen zu tun haben, da die neue Festschreibung immer dem Benutzer zugeordnet wird, der die Festschreibung für das Projekt erstellt hat (wenn die Festschreibung dem aktuellen_Benutzer zugeordnet werden soll).

Vielen Dank im Voraus für jede Hilfe ...

COMMITS CONTROLLER

class CommitsController < ApplicationController
  before_action :find_project

  def new
    @commit = @project.commits.build(user_id: @project.user_id) 
  end

  def show
    @project = Project.find(params[:project_id])
    @commit = Commit.find(params[:id])
  end

  def index
    # @user = User.where(:id => @commit.user_id) first figure out how to set user_id on new commits (its nil now)
    @commits = Commit.paginate(page: params[:page])
  end

  def create
    @project = Project.find(params[:project_id])
    @commit = @project.commits.build(commit_params)
    if @commit.save
      flash[:success] = "You've successfully committed to this project"
      redirect_to project_path(@project)
    else
      render 'new'
    end
  end

  def edit

  end

  def update

  end

  def destroy

  end

  private

    def find_project
      @project = Project.find(params[:project_id])
    end

    def commit_params
      params.require(:commit).permit(:title, :project_id, :user_id)
    end
end

NEW.HTML.ERB (NEUES COMMITS FORMULAR)

<div class="row-fluid">
  <div class="col-md-5 no-pad">
    <h1>Commit a new session file to this project repository</h1>
    <%= bootstrap_form_for @commit, :url => project_commits_path do |f| %>

      <%= render 'shared/error_messages', object: f.object %>

      <%= f.text_field :title %>

      <%= f.hidden_field :user_id %>

      <div class="well">
        <h4>Drag and Drop a file here:</h4>
        <%= image_tag("wavicon-large-grey.png", alt: "add file") %>
      </div>

      <%= f.button "Commit Now! ", class: "btn btn-lg btn-primary" %>
    <% end %>
  </div>
  <div class="col-md-1">
    <%= image_tag "shadow-vert.png" %>
  </div>

</div>

INDEX.HTML.ERB (Liste der Projekt-Commits mit falschem Benutzerprofil-Bild)

<% provide(:title, @commits ) %>

<div class="row-fluid">
  <section class="no-pad col-md-9">

    <%= render :partial => '/projects/project_header' %>

    <h4>Commit History</h4>

    <%= will_paginate %>

    <ul class="commits">

      <% @project.commits.first(5).each do |commit| %> 

        <%= render partial: "commit", object: commit %>

      <% end %>
    </ul>

    <%= will_paginate %>

  </section>

</div>

_COMMIT.HTML.ERB PARTIAL (siehe oben)

<li>
  <%= link_to project_commit_path(@project, commit) do %>
    <h6><%= image_tag commit.user.image_url(:thumb).to_s, :class => "profile-pic-thumb" %><%= commit.title %>...</h6>
    <span class="timestamp pull-right">
      Created <%= time_ago_in_words(commit.created_at) %> ago
      <span class="glyphicon glyphicon-time"></span>
    </span>

  <% end %>
</li>

Wo gehe ich falsch? Der folgende Code sollte den Benutzer anzeigen, der das Commit erstellt hat, und nicht den Benutzer, der das Projekt erstellt hat.

<h6><%= image_tag commit.user.image_url(:thumb).to_s, :class => "profile-pic-thumb" %><%= commit.title %>...</h6>

Antworten auf die Frage(1)

Ihre Antwort auf die Frage