【发布时间】:2014-11-24 11:44:35
【问题描述】:
我有一个 Rails 应用程序作为 iOS 应用程序的后端。它是由第三方开发的,我从来没有使用过 Rails,所以在这里尝试学习。我想让用户可以通过网络访问该应用,并通过主页前端为潜在用户提供有关该应用的一些信息。
听起来很简单,但该应用使用 Devise 进行用户身份验证,当我点击站点根目录时,我收到以下错误消息:
You need to sign in or sign up before continuing.
在 routes.rb 文件中我有以下内容:
root :to => "visitors#index"
devise_for :users
resources :users
在我的访问者控制器中,我添加了一个 before_filter 来尝试打开站点索引:
class VisitorsController < ApplicationController
before_filter :authenticate_user!, :except => [:index]
end
但这并没有什么不同。这里有什么明显的我遗漏的东西,或者我没有掌握的一些概念吗?基本上我希望用户点击站点主页,然后单击“登录”链接,之后他们将可以访问站点的其余部分。
编辑:
我的应用程序控制器:
class ApplicationController < ActionController::Base
respond_to :html, :json
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :null_session, :if => Proc.new { |c| c.request.format == 'application/json'}
before_action :configure_permitted_parameters, if: :devise_controller?
acts_as_token_authentication_handler_for User
protected
def configure_permitted_parameters
devise_parameter_sanitizer.for(:sign_up) << :name
devise_parameter_sanitizer.for(:account_update) << :name
end
end
【问题讨论】:
-
你能发布你的
ApplicationController吗? -
应用程序是在
production还是development中运行?如果production,代码可能会被缓存,并且在重新启动应用服务器之前可能看不到更改。 -
@D-side:它在我的开发机器上运行,但每次更改后我都会重新启动服务器以确保。
标签: ruby-on-rails devise