Ruby on rails 基本HTTP身份验证阻止用户添加书签
我为Ruby on rails 基本HTTP身份验证阻止用户添加书签,ruby-on-rails,devise,basic-authentication,Ruby On Rails,Devise,Basic Authentication,我为咖啡店提供了一个资源,允许用户对收藏的咖啡店和书签咖啡店进行分类 我还在咖啡店控制器上安装了http\u basic\u authenticate\u与,以防止除我之外的任何人向我的数据库写入数据 我目前的设置似乎不允许用户在登录之前真正收藏或书签 我怎样才能避开这件事?我还使用Desive进行用户管理,我是否可以利用它限制对数据库的写入访问,从而允许我删除http\u basic\u authenticate\u with 咖啡店控制器.rb class CoffeeshopsContro
咖啡店
提供了一个资源,允许用户对收藏的
咖啡店和书签
咖啡店进行分类
我还在咖啡店控制器上安装了http\u basic\u authenticate\u与
,以防止除我之外的任何人向我的数据库写入数据
我目前的设置似乎不允许用户在登录之前真正收藏
或书签
我怎样才能避开这件事?我还使用Desive进行用户管理,我是否可以利用它限制对数据库的写入访问,从而允许我删除http\u basic\u authenticate\u with
咖啡店控制器.rb
class CoffeeshopsController
我尝试将其更新为
[:index,:show,:put]
,但这并没有产生任何影响。在中,除了
之外,您应该列出控制器操作,而不是http方法,因此如下所示:
class CoffeeshopsController < ApplicationController
http_basic_authenticate_with name: "*******", password: "*******", except: [:index, :favorite, :bookmark]
def index
# list of coffeeshops without authentication
end
def new
# requires authentication
end
def create
# requires authentication
end
def favorite
# endpoint to mark coffeeshop as favourite without authentication
end
def bookmark
# endpoint to bookmark a coffeeshop without authentication
end
...
end
class CoffeeshopsController
如果您有一个用户帐户系统,例如使用Desive,那么您可能根本不需要任何http\u basic\u身份验证,并且在筛选之前使用进行身份验证。
。是的,我需要留出一些时间阅读有关设置角色的内容。
class CoffeeshopsController < ApplicationController
http_basic_authenticate_with name: "*******", password: "*******", except: [:index, :favorite, :bookmark]
def index
# list of coffeeshops without authentication
end
def new
# requires authentication
end
def create
# requires authentication
end
def favorite
# endpoint to mark coffeeshop as favourite without authentication
end
def bookmark
# endpoint to bookmark a coffeeshop without authentication
end
...
end