我正在尝试使用rails中的surveyor gem进行调查。我想利用用户ID来跟踪哪个用户创建调查,以及哪个用户在哪个调查中给出了什么响应。在轨道上使用Surveyor gem进行调查的实施
问题是我没有使用设计宝石用于我的用户登录和注册。我手动建立它。 Surveyor gem使用Devise的helper方法current_user来返回有关当前用户的详细信息。
因为,我没有使用设计,我不知道在哪里添加辅助方法current_user。
我不太确定要发布什么代码,因此请评论所需的详细信息。我将根据需要编辑我的帖子。
谢谢!
application_controller.rb
class ApplicationController < ActionController::Base
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception
before_filter :authorize
helper_method :current_user
protected
def authorize
return true if ((self.class == SessionsController)|| (self.class == UsersController && (self.action_name == "new" || self.action_name == "create")))
unless (User.find_by_id(session[:user_id]))
redirect_to url_for(:controller => :sessions , :action => :new), alert: "You need to be logged in."
end
end
def current_user
@current_user = User.find(session[:user_id])
end
end
这里是其使用方法CURRENT_USER测量员宝石控制器的链接:https://github.com/kjayma/surveyor_gui/blob/master/app/controllers/surveyor_gui/survey_controller.rb
有什么好运气? –