前提・実現したいこと
Ajaxの非同期通信(remote:true)しているときに、コントローラーでアップデートする前に、ビューで取得していないupdate_user_idのパラメータを追加したいです。
調べるとAjaxで通信する際に、コントローラー内でcurrent_userは取得できないとのことでした。
どのサイトを見ても、これだ!という解決方法がなかったので、もし、良い方法を御存知でしたら共有いただければと思います。
#remote:trueでAjax通信をしたさいにcurrent_userがnilになる。 def update company_params[:updated_user_id] = current_user.id #deviseを利用 respond_to do |format| if @company.update(company_params) format.html { redirect_to company_path, notice: 'Company was successfully updated.' } format.json { render :show, status: :ok, location: @company } else format.html { render :edit } format.json { render json: @company.errors, status: :unprocessable_entity } end end end
もしくはremote:trueではない方法でSPAを実現したほうが良いのでしょうか?
どうぞよろしくお願いいたします。
実現できそうな方法
https://stackoverflow.com/questions/37779359/how-to-update-users-with-ajax-using-devise
補足情報(FW/ツールのバージョンなど)
下記の質問で、remote=>trueがない場合は解決いたしました。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。