0
사용자가 앱의 알림 드롭 다운을 클릭 할 때마다 status
의 알림을 read
으로 업데이트하려고합니다. 컨트롤러의 create
방법을 트리거한다Rails 4는 ArgumentError (잘못된 인수 수 (1에 대해 2)) : 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