railsでtwitterのようなSNSを作っています。scaffoldを使用して投稿の流れを作成したのですがその投稿にユーザー情報を追加するにはどのようにすればよろしいでしょうか?deviseのジェムを使用しているのですが私のテキストではscaffoldを使用しないやり方なのでどこにどのような記述をすればよいかわからずに困っております。
テキスト:
def create
Tweet.create(name: tweet_params[:name], image: tweet_params[:image], text: tweet_params[:text], user_id: current_user.id)
end
このようにcreateを使用して最後にcurrent_userを使用しています。しかし、scaffoldを使用した私の方は
def create
@spot = Spot.new(spot_params)
respond_to do |format| if @spot.save format.html { redirect_to @spot, notice: '投稿が完了しました!!' } format.json { render :show, status: :created, location: @spot } else format.html { render :new } format.json { render json: @spot.errors, status: :unprocessable_entity } end end
end
このようになっておりどこにいれればよいかわかりません。spot_paramsは以下のようになっています。
def spot_params
params.require(:spot).permit(:name, :place, :price, :immpression)
end
つたない文章ですがよろしくお願いします。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2015/10/28 10:53