前提・実現したいこと
現在、学生と企業のマッチングサービスを作っています、
そこで、企業が学生に対して、コメントつきでいいねする機能を実装しているのですが、うまくいきません。
発生している問題・エラーメッセージ
いいね機能の実装をすることはできるのですが、contentと一緒に保存しようとすると、contentがnilになってしまい、saveをすることができません。
該当のソースコード
Ruby
1class UserThanksController < ApplicationController 2 def new 3 @company = Company.find_by(id: params[:id]) 4 @user_thank = @company.user_thanks.new 5 6 end 7 8 def create 9 @company = Company.find_by(id: params[:id]) 10 @user_thank = @company.user_thanks.new(user_thanks_params) 11 if @user_thank.save(user_thanks_params) 12 13 redirect_to '' 14 15 end 16 17 end 18 19private 20 21def user_thanks_params 22 params.require(:user_thank).permit(:content,:conmpany_id,:user_id) 23end 24
class User < ApplicationRecord # Include default devise modules. Others available are: # :confirmable, :lockable, :timeoutable, :trackable and :omniauthable devise :database_authenticatable, :registerable, :recoverable, :rememberable, :validatable has_many :user_thanks, dependent: :destroy end
class Company < ApplicationRecord # Include default devise modules. Others available are: # :confirmable, :lockable, :timeoutable, :trackable and :omniauthable devise :database_authenticatable, :registerable, :recoverable, :rememberable, :validatable mount_uploader :image, ImageUploader has_many :user_thanks, dependent: :destroy end
class UserThank < ApplicationRecord belongs_to :user belongs_to :company validates :user_id, presence: true validates :company_id, presence: true validates :content, presence: true end
よろしくお願いします。
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/11/19 09:09