我正在尝试为我的用户创建个人资料页面,并希望为用户提供一些复选框,以便即时更新个人资料而无需保存。
我正在尝试使用复选框来调用咖啡脚本并执行ajax调用来更新用户控制器中的功能。但它显示" PATCH localhost:3000/404(未找到)"在控制台中。
视图
- @sectors = ['music', 'math', 'chinese']
- @sectors.each do |sector|
p
= sector
= check_box_tag sector, sector, false, class: "interest-check-box", data: { user_id: current_user.id, interest: sector }
IN JS.COFFEE
$(".interest-check-box").click ->
console.log("Checked")
checked = undefined
if $(this).is(":checked")
checked = true
else
checked = false
$.ajax
type: "PATCH"
url: "/users/" + $(this).data('user-id')
dataType: "json"
data:
_method: "PUT"
id: $(this).data("user-id")
checked: checked
interest: $(this).data("interest")
return
IN CONTROLLER,我只想先测试重定向,它被调用但总是PATCH localhost:3000/404(未找到)
class UsersController < ApplicationController
def show
@member = User.find(params[:id])
end
def destroy
@user = User.find(params[:id])
if @user.destroy
redirect_to root_url, notice: "User deleted."
end
end
def update
redirect_to root_path
end
end