0
通知のstatus
をread
に更新したいときは、ユーザーがアプリの通知プルダウンをクリックするようにします。コントローラのcreate
方法をトリガーするRails 4はArgumentError(引数が間違っている(2の場合1)):AJAX POSTを使って更新するとき
class Api::V1::NotificationsController < ApiController
before_action :authenticate_user!
def index
@notifications = Notification.where(user_id: current_user.id).order(created_at: :desc)
render_success @notifications
end
def create
Notification.update_all({status: "read"}, {user_id: current_user.id})
end
end
とjQueryコード:ここ
は、コントローラコードであるStarted POST "/api/v1/notifications" for ::1 at 2017-09-19 16:27:53 +0800
Processing by Api::V1::NotificationsController#create as */*
User Load (0.6ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 ORDER BY "users"."id" ASC LIMIT 1 [["id", 13]]
Completed 500 Internal Server Error in 6ms (ActiveRecord: 0.6ms)
ArgumentError (wrong number of arguments (2 for 1)):
app/controllers/api/v1/notifications_controller.rb:11:in `create'
:残念なことに
$('.notifications-menu').on('shown.bs.dropdown', function() {
console.log('Opened notifications');
$.post('/api/v1/notifications');
})
、このエラーを返し
これは機能しました。ありがとうございます:) 10分で受け入れられる回答としてこれを選択します –
あなたを助けてくれてうれしいです) – cnnr