我試圖將我創建的用戶與Devise關聯到帖子。但是,當我嘗試創建以用戶身份登錄的帖子時,我得到了標題中提到的錯誤。非常感謝你:)未知屬性`user_id'
class PostsController < ApplicationController
def index
@posts = Post.all
end
def new
@post = Post.new
end
def create
@post = Post.new(params.require(:post).permit(:task))
@post.user = current_user
if @post.save
redirect_to @post, alert:"Post created successfully."
else
redirect_to new_post_path, alert: "Error creating post."
end
end
def show
@post = Post.find(params[:id])
end
end
class Post < ActiveRecord::Base
validates_presence_of :task
belongs_to :user
end