ruby-on-rails-3 – rails为特定页面设计401未授权

前端之家收集整理的这篇文章主要介绍了ruby-on-rails-3 – rails为特定页面设计401未授权前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我无法辨别为什么我的应用程序返回401 Unauthorized.我的机构控制器中的其他操作在没有登录的情况下正常工作.但是,这个和另一个页面返回401.如果登录,这些页面工作得非常好,但它们不应该要求登录.我甚至已经这样做了至于清空视图和动作,但页面仍然返回401.当通过fiddler调试时,我只是收到302重定向.

我尝试过在其他地方进行研究,并尝试了Warden authentication recalls 401 Unauthorized解决方案但没有成功.

安慰

Started GET "/institutions/3" for 127.0.0.1 at 2013-04-25 14:38:15 -0400
    Processing by InstitutionsController#show as HTML
      Parameters: {"id"=>"3"}
      ←[1m←[36mInstitution Load (0.0ms)←[0m  ←[1mSELECT `institutions`.* FROM `institutions` WHERE `institutions`.`id` = 3 LIMIT 1←[0m

Load data...
Load assets...

然后我提交表单,方法设置为GET

Started GET "/visit/schedule/preview?utf8=%E2%9C%93&selected_ids=4693" for 127.0.0.1 at 2013
-04-25 14:28:53 -0400
Processing by InstitutionsController#previewselectedvisits as HTML
  Parameters: {"utf8"=>"√","selected_ids"=>"4693"}
Completed 401 Unauthorized in 0ms

Started GET "/users/sign_in" for 127.0.0.1 at 2013-04-25 14:28:53 -0400
Processing by Devise::SessionsController#new as HTML
  Rendered devise/sessions/new.html.erb within layouts/application (15.6ms)
  Rendered auth/_login.html.erb (0.0ms)
  Rendered auth/_loginmodal.html.erb (0.0ms)
  Rendered shared/_navbarout.html.erb (0.0ms)
  Rendered shared/_navbar.html.erb (0.0ms)
  ←[1m←[36mInstitution Load (0.0ms)←[0m  ←[1mSELECT name FROM `institutions` ←[0m
  Rendered search/_searchbar.html.erb (0.0ms)
  Rendered search/_searchresults.html.erb (0.0ms)
  Rendered shared/_footer.html.erb (0.0ms)
Completed 200 OK in 140ms (Views: 46.8ms | ActiveRecord: 15.6ms)

Load assets...

相关路线

devise_for :users
match 'visit/schedule/preview' => 'institutions#previewselectedvisits',:as => :preview_visits,:via => :get
match "institutions/:id" => "institutions#show",:as => :show_institution

耙路线

new_user_session GET    /users/sign_in(.:format)                             devise/sessions#new
              user_session POST   /users/sign_in(.:format)                             devise/sessions#create
      destroy_user_session DELETE /users/sign_out(.:format)                            devise/sessions#destroy
             user_password POST   /users/password(.:format)                            devise/passwords#create
         new_user_password GET    /users/password/new(.:format)                        devise/passwords#new
        edit_user_password GET    /users/password/edit(.:format)                       devise/passwords#edit
                           PUT    /users/password(.:format)                            devise/passwords#update
  cancel_user_registration GET    /users/cancel(.:format)                              devise_invitable/registrations#cancel
         user_registration POST   /users(.:format)                                     devise_invitable/registrations#create
     new_user_registration GET    /users/sign_up(.:format)                             devise_invitable/registrations#new
    edit_user_registration GET    /users/edit(.:format)                                devise_invitable/registrations#edit
                           PUT    /users(.:format)                                     devise_invitable/registrations#update
                           DELETE /users(.:format)                                     devise_invitable/registrations#destroy
         user_confirmation POST   /users/confirmation(.:format)                        devise/confirmations#create
     new_user_confirmation GET    /users/confirmation/new(.:format)                    devise/confirmations#new
                           GET    /users/confirmation(.:format)                        devise/confirmations#show
               user_unlock POST   /users/unlock(.:format)                              devise/unlocks#create
           new_user_unlock GET    /users/unlock/new(.:format)                          devise/unlocks#new
                           GET    /users/unlock(.:format)                              devise/unlocks#show
    accept_user_invitation GET    /users/invitation/accept(.:format)                   devise/invitations#edit
    remove_user_invitation GET    /users/invitation/remove(.:format)                   devise/invitations#destroy
           user_invitation POST   /users/invitation(.:format)                          devise/invitations#create
       new_user_invitation GET    /users/invitation/new(.:format)                      devise/invitations#new
                           PUT    /users/invitation(.:format)                          devise/invitations#update
            preview_visits GET    /visit/schedule/preview(.:format)                    institutions#previewselectedvisits
          show_institution        /institutions/:id(.:format)                          institutions#show
          vote_institution        /institutions/:id/vote/:visittype_id(.:format)       institutions#vote
                                  /institutions/:id/:offset(.:format)                  institutions#show
              institutions        /institutions(.:format)                              institutions#index
           schedule_visits        /schedule(.:format)                                  institutions#index
              auth_failure        /auth/failure(.:format)                              services#failure
                                  /auth/:service/:callback(.:format)                   services#create
                  services GET    /services(.:format)                                  services#index
                           POST   /services(.:format)                                  services#create
                   service DELETE /services/:id(.:format)                              services#destroy
                login_user        /users/login(.:format)                               users#login
             myvisits_user        /users/myvisits(.:format)                            users#myvisits
       email_myvisits_user        /users/myvisits/email(.:format)                      users#emailmyvisits
    remove_visit_from_user        /users/removevisit/:id/:user_id(.:format)            users#rmvisit
            addvisits_user        /users/addvisits(.:format)                           users#addvisits
          changevisit_user        /users/visits/:user_id/:visit_id/:is_going(.:format) users#toggle_user_going_on_visit
        add_family_to_user        /users/invite(.:format)                              users#addfamilymember
add_family_default_to_user        /users/profile/addfamilymemberdefault(.:format)      users#addfamilymember_default
   remove_family_from_user        /users/profile/removefamilymember(.:format)          users#rmfamilymember
       update_profile_user        /users/profile/update(.:format)                      users#update
 update_profile_other_user        /users/profile/update/:id(.:format)                  users#update
         edit_profile_user        /users/profile/edit(.:format)                        users#edit
         show_profile_user        /users/profile(.:format)                             users#show
                     users        /users(.:format)                                     users#show
                  families GET    /families(.:format)                                  families#index
                           POST   /families(.:format)                                  families#create
                new_family GET    /families/new(.:format)                              families#new
               edit_family GET    /families/:id/edit(.:format)                         families#edit
                    family GET    /families/:id(.:format)                              families#show
                           PUT    /families/:id(.:format)                              families#update
                           DELETE /families/:id(.:format)                              families#destroy
                    visits        /visits(.:format)                                    visits#index
                   company        /company(.:format)                                   company#aboutus
                       edu        /edu(.:format)                                       edu#index
                      root        /                                                    institutions#index

的Gemfile

source 'https://rubygems.org'
gem 'rails','3.2.12'
gem 'MysqL2'
gem 'execjs'
group :assets do
  gem 'sass-rails','~> 3.2.3'
  gem 'coffee-rails','~> 3.2.1'
  gem 'uglifier','>= 1.0.3'
end

gem 'jquery-rails'
gem 'simple_form'

gem 'devise'
gem 'devise_invitable'
gem 'omniauth'
gem "omniauth-google-oauth2"
gem 'omniauth-linkedin-oauth2'
gem 'omniauth-facebook'

#in-place editing
gem 'best_in_place'

#email template convert to inline
gem 'roadie'

#amazon web services and images
gem 'paperclip'
gem 'aws-sdk'

解决方法

检查INSTITController和ApplicationController的代码 – 查找包含current_user或before_filter的语句
class InstitutionsController < ApplicationController
    before_filter :login_required,:only => [:method1,:method2]
    ...
 end

可能是您尝试调用方法列为要求身份验证,但您尚未登录.

你还可以在其中发布带有预览方法的INSTITController的摘录吗?

另一个可能的问题是您的路线可能定义不正确:

match 'visit/schedule/preview' => 'institutions#previewselectedvisits',:via => :get

INSTITController真的有一个名为previewselectedvisits的方法吗?

猜你在找的Ruby相关文章