Ruby on rails Rails Desive-如何打开对站点根目录的访问
我有一个Rails应用程序作为iOS应用程序的后端。它是由第三方开发的,我从未使用过Rails,所以我在这里尝试学习。我想让用户可以访问web应用程序,并为潜在用户提供有关该应用程序的一些信息 听起来很简单,但应用程序正在使用Desive进行用户身份验证,当我点击网站根目录时,我收到以下错误消息:Ruby on rails Rails Desive-如何打开对站点根目录的访问,ruby-on-rails,devise,Ruby On Rails,Devise,我有一个Rails应用程序作为iOS应用程序的后端。它是由第三方开发的,我从未使用过Rails,所以我在这里尝试学习。我想让用户可以访问web应用程序,并为潜在用户提供有关该应用程序的一些信息 听起来很简单,但应用程序正在使用Desive进行用户身份验证,当我点击网站根目录时,我收到以下错误消息: You need to sign in or sign up before continuing. 在routes.rb文件中,我有以下内容: root :to => "visitors#in
You need to sign in or sign up before continuing.
在routes.rb文件中,我有以下内容:
root :to => "visitors#index"
devise_for :users
resources :users
acts_as_token_authentication_handler_for User, :except => [:index]
在我的访问者控制器中,我添加了一个before_过滤器,以尝试打开站点索引:
class VisitorsController < ApplicationController
before_filter :authenticate_user!, :except => [:index]
end
class VisitorsController[:索引]
结束
但这没什么区别。这里有什么明显的我遗漏的,或者我没有领会的概念吗?基本上,我希望用户点击网站主页,然后点击“登录”链接,然后他们就可以访问网站的其余部分
编辑:
我的应用程序控制器:
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
class ApplicationControllerProc.new{c | c.request.format=='application/json'}保护_免受伪造
在\u操作之前:配置\u允许的\u参数,如果::设计\u控制器?
充当用户的\u令牌\u身份验证\u处理程序\u
受保护的
def配置\u允许的\u参数
designe_参数_消毒剂。对于(:注册)来自designe的
,它似乎描述了您的示例。您可以在routes.rb文件中创建两个根。一个用于经过身份验证的用户,一个用于未经身份验证的用户:
authenticated :user do
root :to => 'visitors#some_action', :as => :authenticated_root
end
root :to => 'visitors#index'
但是,请发布您的应用程序控制器
,因为您的示例代码应该起作用,问题可能就在那里。如果其他人也有同样的问题-罪魁祸首是application\u controller.rb中的以下行:
acts_as_token_authentication_handler_for User
它是简单的\u令牌\u身份验证Gem()的一部分
为了修复对根页面的匿名访问,我将其更改为:
root :to => "visitors#index"
devise_for :users
resources :users
acts_as_token_authentication_handler_for User, :except => [:index]
你能发布你的应用程序控制器吗
?该应用程序是在生产中运行还是在开发中运行?如果production
,则代码可能会被缓存,并且在重新启动应用程序服务器之前,更改可能不可见。@D-side:它正在我的开发计算机上运行,但我在每次更改后都会重新启动服务器以确保安全。我尝试了此操作,但没有更改。我已经在上面添加了我的应用程序控制器。@aritchie您能尝试删除您的而不是并添加跳过之前的过滤器:验证用户!,:only=>:index
没有更改,仍然得到错误。在使用“rails s”运行站点的终端中,我收到消息:“Started get”/“for 127.0.0.1于2014-11-24 12:36:02+0000由VisitorsController处理#以HTML形式索引在0毫秒内完成”