title: Rails Rollback Transaction
body: <p>I have problems with my Rails Block. After I implemented a comment-section I am not able to create posts anymore. The console gives me a rollback transaction. So I did</p>
  
  <pre><code>p = Post.new
  p.valid? # false
  p.errors.messages
  </code></pre>
  
  <p>It seems I have some validation problems with user <code>:user=&gt;["must exist"]</code>. But before I implemented comments it did work. Can someone help me out?</p>
  
  <p><strong>User.rb</strong></p>
  
  <pre><code>class User &lt; ApplicationRecord
    has_many :posts
    # Include default devise modules. Others available are:
    # :confirmable, :lockable, :timeoutable and :omniauthable
    devise :database_authenticatable, :registerable,
          :recoverable, :rememberable, :trackable, :validatable
  end
  </code></pre>
  
  <p><strong>Post.rb</strong></p>
  
  <pre><code>class Post &lt; ApplicationRecord
    belongs_to :user
    has_many :comments, dependent: :destroy
  
    validates :title, presence: true, length: {minimum: 5}
    validates :body, presence: true
  
  
    has_attached_file :image  #, :styles =&gt; { :medium =&gt; "300x300&gt;", :thumb =&gt; "100x100&gt;" }
    validates_attachment_content_type :image, :content_type =&gt; /\Aimage\/.*\Z/
  end
  </code></pre>
  
  <p><strong>Post-migrate</strong></p>
  
  <pre><code>class CreatePosts &lt; ActiveRecord::Migration[5.1]
    def change
       create_table :posts do |t|
       t.string :title
       t.text :body
  
       t.timestamps
       end
     end
   end
  </code></pre>
  
  <p><strong>Post_controller</strong></p>
  
  <pre><code>class PostsController &lt; ApplicationController
    def index
      @posts = Post.all.order("created_at DESC")
    end
  
    def new
      @post = Post.new
    end
  
    def create
      @post = Post.new(post_params)
  
      if @post.save
        redirect_to @post
      else
        render 'new'
      end
    end
  
    def show
      @post = Post.find(params[:id])
    end
  
    def edit
      @post = Post.find(params[:id])
    end
  
    def update
      @post = Post.find(params[:id])
  
      if @post.update(post_params)
        redirect_to @post
      else
        render 'edit'
      end
    end
  
    def destroy
      @post = Post.find(params[:id])
      @post.destroy
  
      redirect_to posts_path
    end
  
    private
  
    def post_params
      params.require(:post).permit(:title, :body, :theme)
    end
  end
  </code></pre>