मैं RoR पर वसीयत का उपयोग कर रहा हूँ। रीसेट पासवर्ड में, यदि आप गलत ईमेल डालते हैं, तो ऐप तुरंत कुछ त्रुटि दिखाएगा और मूल यूआरएल को रीडायरेक्ट करेगा।

मेरे ऐप में, मूल यूआरएल इस तरह है।

http://localhost:3000/en/users/password/new

गलत ईमेल डालने पर किसी तरह यह पुनर्निर्देशित हो जाता है

http://localhost:3000/en/users/password/

आम तौर पर, यह हो सकता है

http://localhost:3000/en/users/password/new

मैं समझ नहीं पा रहा हूं कि ऐसा क्यों हो सकता है। और जानना चाहेंगे कि क्या गलत है। कोई मेरी मदद करो।

श्रेष्ठ

[परिशिष्ट] यहां पासवर्ड से संबंधित मेरा मार्ग है।

$ rake routes
(in /Users/takamizawanoriaki/vegewel)
                               Prefix Verb     URI Pattern                                                             Controller#Action
                           home_index GET      /home/index(.:format)                                                   home#index
user_google_oauth2_omniauth_authorize GET|POST /users/auth/google_oauth2(.:format)                                     users/omniauth_callbacks#passthru
 user_google_oauth2_omniauth_callback GET|POST /users/auth/google_oauth2/callback(.:format)                            users/omniauth_callbacks#google_oauth2
     user_facebook_omniauth_authorize GET|POST /users/auth/facebook(.:format)                                          users/omniauth_callbacks#passthru
      user_facebook_omniauth_callback GET|POST /users/auth/facebook/callback(.:format)                                 users/omniauth_callbacks#facebook
      user_twitter_omniauth_authorize GET|POST /users/auth/twitter(.:format)                                           users/omniauth_callbacks#passthru
       user_twitter_omniauth_callback GET|POST /users/auth/twitter/callback(.:format)                                  users/omniauth_callbacks#twitter
                    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
                             shortcut GET      /shortcut/:id(.:format)                                                 shortcut#show
                                      GET      /(:locale)(.:format)                                                    frontpage#index {:locale=>/en|ja/}
                                 near GET      (/:locale)/near(.:format)                                               frontpage#near {:locale=>/en|ja/}
                    restaurant_nearby GET      (/:locale)/restaurant_nearby(.:format)                                  area#restaurant_nearby {:locale=>/en|ja/}
                         notification GET      (/:locale)/notification(.:format)                                       application#set_checked_notification {:locale=>/en|ja/}
                  notification_create GET      (/:locale)/notification/create(.:format)                                notification#create {:locale=>/en|ja/}
                   notification_index GET      (/:locale)/notification/index(.:format)                                 notification#index {:locale=>/en|ja/}
                           restaurant GET      (/:locale)/restaurant(.:format)                                         restaurant#index {:locale=>/en|ja/}
                                      GET      (/:locale)/restaurant/:id(.:format)                                     restaurant#show {:locale=>/en|ja/}
                                 menu GET      (/:locale)/menu(.:format)                                               menu#index {:locale=>/en|ja/}
                                      GET      (/:locale)/menu/:id(.:format)                                           menu#show {:locale=>/en|ja/}
                                 area GET      (/:locale)/area(.:format)                                               area#index {:locale=>/en|ja/}
                                      GET      (/:locale)/area/:id(.:format)                                           area#show {:locale=>/en|ja/}
                      restaurant_type GET      (/:locale)/restaurant_type(.:format)                                    restaurant_type#index {:locale=>/en|ja/}
                                      GET      (/:locale)/restaurant_type/:id(.:format)                                restaurant_type#show {:locale=>/en|ja/}
                              cuisine GET      (/:locale)/cuisine(.:format)                                            cuisine#index {:locale=>/en|ja/}
                                      GET      (/:locale)/cuisine/:id(.:format)                                        cuisine#show {:locale=>/en|ja/}
                              product GET      (/:locale)/product(.:format)                                            product#index {:locale=>/en|ja/}
                                      GET      (/:locale)/product/:id(.:format)                                        product#show {:locale=>/en|ja/}
                                 shop GET      (/:locale)/shop(.:format)                                               shop#index {:locale=>/en|ja/}
                                      GET      (/:locale)/shop/:id(.:format)                                           shop#show {:locale=>/en|ja/}
                            prefstate GET      (/:locale)/prefstate(.:format)                                          prefstate#index {:locale=>/en|ja/}
                                      GET      (/:locale)/prefstate/:id(.:format)                                      prefstate#show {:locale=>/en|ja/}
                                      GET      (/:locale)/style_image/:id(.:format)                                    style#show_image {:locale=>/en|ja/}
                               search GET      (/:locale)/search(.:format)                                             search#index {:locale=>/en|ja/}
                                batch GET      (/:locale)/batch(.:format)                                              batch#index {:locale=>/en|ja/}
                              privacy GET      (/:locale)/privacy(.:format)                                            privacy#index {:locale=>/en|ja/}
                                terms GET      (/:locale)/terms(.:format)                                              terms#index {:locale=>/en|ja/}
                             about_us GET      (/:locale)/about_us(.:format)                                           about_us#index {:locale=>/en|ja/}
                                 feed GET      (/:locale)/feed(.:format)                                               feed#feed {:format=>/rss/, :locale=>/en|ja/}
                    knowledge_sprouts GET      (/:locale)/knowledge_sprouts(.:format)                                  knowledge_sprouts#index {:locale=>/en|ja/}
                                      POST     (/:locale)/knowledge_sprouts(.:format)                                  knowledge_sprouts#create {:locale=>/en|ja/}
                 new_knowledge_sprout GET      (/:locale)/knowledge_sprouts/new(.:format)                              knowledge_sprouts#new {:locale=>/en|ja/}
                edit_knowledge_sprout GET      (/:locale)/knowledge_sprouts/:id/edit(.:format)                         knowledge_sprouts#edit {:locale=>/en|ja/}
                     knowledge_sprout GET      (/:locale)/knowledge_sprouts/:id(.:format)                              knowledge_sprouts#show {:locale=>/en|ja/}
                                      PATCH    (/:locale)/knowledge_sprouts/:id(.:format)                              knowledge_sprouts#update {:locale=>/en|ja/}
                                      PUT      (/:locale)/knowledge_sprouts/:id(.:format)                              knowledge_sprouts#update {:locale=>/en|ja/}
                                      DELETE   (/:locale)/knowledge_sprouts/:id(.:format)                              knowledge_sprouts#destroy {:locale=>/en|ja/}
                              answers GET      (/:locale)/answers(.:format)                                            answers#index {:locale=>/en|ja/}
                                      POST     (/:locale)/answers(.:format)                                            answers#create {:locale=>/en|ja/}
                           new_answer GET      (/:locale)/answers/new(.:format)                                        answers#new {:locale=>/en|ja/}
                          edit_answer GET      (/:locale)/answers/:id/edit(.:format)                                   answers#edit {:locale=>/en|ja/}
                               answer GET      (/:locale)/answers/:id(.:format)                                        answers#show {:locale=>/en|ja/}
                                      PATCH    (/:locale)/answers/:id(.:format)                                        answers#update {:locale=>/en|ja/}
                                      PUT      (/:locale)/answers/:id(.:format)                                        answers#update {:locale=>/en|ja/}
                                      DELETE   (/:locale)/answers/:id(.:format)                                        answers#destroy {:locale=>/en|ja/}
                              reviews GET      (/:locale)/reviews(.:format)                                            reviews#index {:locale=>/en|ja/}
                                      POST     (/:locale)/reviews(.:format)                                            reviews#create {:locale=>/en|ja/}
                           new_review GET      (/:locale)/reviews/new(.:format)                                        reviews#new {:locale=>/en|ja/}
                          edit_review GET      (/:locale)/reviews/:id/edit(.:format)                                   reviews#edit {:locale=>/en|ja/}
                               review GET      (/:locale)/reviews/:id(.:format)                                        reviews#show {:locale=>/en|ja/}
                                      PATCH    (/:locale)/reviews/:id(.:format)                                        reviews#update {:locale=>/en|ja/}
                                      PUT      (/:locale)/reviews/:id(.:format)                                        reviews#update {:locale=>/en|ja/}
                                      DELETE   (/:locale)/reviews/:id(.:format)                                        reviews#destroy {:locale=>/en|ja/}
                      product_reviews GET      (/:locale)/product_reviews(.:format)                                    product_reviews#index {:locale=>/en|ja/}
                                      POST     (/:locale)/product_reviews(.:format)                                    product_reviews#create {:locale=>/en|ja/}
                   new_product_review GET      (/:locale)/product_reviews/new(.:format)                                product_reviews#new {:locale=>/en|ja/}
                  edit_product_review GET      (/:locale)/product_reviews/:id/edit(.:format)                           product_reviews#edit {:locale=>/en|ja/}
                       product_review GET      (/:locale)/product_reviews/:id(.:format)                                product_reviews#show {:locale=>/en|ja/}
                                      PATCH    (/:locale)/product_reviews/:id(.:format)                                product_reviews#update {:locale=>/en|ja/}
                                      PUT      (/:locale)/product_reviews/:id(.:format)                                product_reviews#update {:locale=>/en|ja/}
                                      DELETE   (/:locale)/product_reviews/:id(.:format)                                product_reviews#destroy {:locale=>/en|ja/}
                        relationships POST     (/:locale)/relationships(.:format)                                      relationships#create {:locale=>/en|ja/}
                         relationship DELETE   (/:locale)/relationships/:id(.:format)                                  relationships#destroy {:locale=>/en|ja/}
                       review_upholds POST     (/:locale)/reviews/:review_id/upholds(.:format)                         upholds#create {:locale=>/en|ja/}
                        review_uphold DELETE   (/:locale)/reviews/:review_id/upholds/:id(.:format)                     upholds#destroy {:locale=>/en|ja/}
                                      GET      (/:locale)/reviews(.:format)                                            reviews#index {:locale=>/en|ja/}
                                      POST     (/:locale)/reviews(.:format)                                            reviews#create {:locale=>/en|ja/}
                                      GET      (/:locale)/reviews/new(.:format)                                        reviews#new {:locale=>/en|ja/}
                                      GET      (/:locale)/reviews/:id/edit(.:format)                                   reviews#edit {:locale=>/en|ja/}
                                      GET      (/:locale)/reviews/:id(.:format)                                        reviews#show {:locale=>/en|ja/}
                                      PATCH    (/:locale)/reviews/:id(.:format)                                        reviews#update {:locale=>/en|ja/}
                                      PUT      (/:locale)/reviews/:id(.:format)                                        reviews#update {:locale=>/en|ja/}
                                      DELETE   (/:locale)/reviews/:id(.:format)                                        reviews#destroy {:locale=>/en|ja/}
               product_review_upholds POST     (/:locale)/product_reviews/:product_review_id/upholds(.:format)         upholds#create {:locale=>/en|ja/}
                product_review_uphold DELETE   (/:locale)/product_reviews/:product_review_id/upholds/:id(.:format)     upholds#destroy {:locale=>/en|ja/}
                                      GET      (/:locale)/product_reviews(.:format)                                    product_reviews#index {:locale=>/en|ja/}
                                      POST     (/:locale)/product_reviews(.:format)                                    product_reviews#create {:locale=>/en|ja/}
                                      GET      (/:locale)/product_reviews/new(.:format)                                product_reviews#new {:locale=>/en|ja/}
                                      GET      (/:locale)/product_reviews/:id/edit(.:format)                           product_reviews#edit {:locale=>/en|ja/}
                                      GET      (/:locale)/product_reviews/:id(.:format)                                product_reviews#show {:locale=>/en|ja/}
                                      PATCH    (/:locale)/product_reviews/:id(.:format)                                product_reviews#update {:locale=>/en|ja/}
                                      PUT      (/:locale)/product_reviews/:id(.:format)                                product_reviews#update {:locale=>/en|ja/}
                                      DELETE   (/:locale)/product_reviews/:id(.:format)                                product_reviews#destroy {:locale=>/en|ja/}
                       answer_upholds POST     (/:locale)/answers/:answer_id/upholds(.:format)                         upholds#create {:locale=>/en|ja/}
                        answer_uphold DELETE   (/:locale)/answers/:answer_id/upholds/:id(.:format)                     upholds#destroy {:locale=>/en|ja/}
                                      GET      (/:locale)/answers(.:format)                                            answers#index {:locale=>/en|ja/}
                                      POST     (/:locale)/answers(.:format)                                            answers#create {:locale=>/en|ja/}
                                      GET      (/:locale)/answers/new(.:format)                                        answers#new {:locale=>/en|ja/}
                                      GET      (/:locale)/answers/:id/edit(.:format)                                   answers#edit {:locale=>/en|ja/}
                                      GET      (/:locale)/answers/:id(.:format)                                        answers#show {:locale=>/en|ja/}
                                      PATCH    (/:locale)/answers/:id(.:format)                                        answers#update {:locale=>/en|ja/}
                                      PUT      (/:locale)/answers/:id(.:format)                                        answers#update {:locale=>/en|ja/}
                                      DELETE   (/:locale)/answers/:id(.:format)                                        answers#destroy {:locale=>/en|ja/}
             knowledge_sprout_upholds POST     (/:locale)/knowledge_sprouts/:knowledge_sprout_id/upholds(.:format)     upholds#create {:locale=>/en|ja/}
              knowledge_sprout_uphold DELETE   (/:locale)/knowledge_sprouts/:knowledge_sprout_id/upholds/:id(.:format) upholds#destroy {:locale=>/en|ja/}
                                      GET      (/:locale)/knowledge_sprouts(.:format)                                  knowledge_sprouts#index {:locale=>/en|ja/}
                                      POST     (/:locale)/knowledge_sprouts(.:format)                                  knowledge_sprouts#create {:locale=>/en|ja/}
                                      GET      (/:locale)/knowledge_sprouts/new(.:format)                              knowledge_sprouts#new {:locale=>/en|ja/}
                                      GET      (/:locale)/knowledge_sprouts/:id/edit(.:format)                         knowledge_sprouts#edit {:locale=>/en|ja/}
                                      GET      (/:locale)/knowledge_sprouts/:id(.:format)                              knowledge_sprouts#show {:locale=>/en|ja/}
                                      PATCH    (/:locale)/knowledge_sprouts/:id(.:format)                              knowledge_sprouts#update {:locale=>/en|ja/}
                                      PUT      (/:locale)/knowledge_sprouts/:id(.:format)                              knowledge_sprouts#update {:locale=>/en|ja/}
                                      DELETE   (/:locale)/knowledge_sprouts/:id(.:format)                              knowledge_sprouts#destroy {:locale=>/en|ja/}
                     new_user_session GET      (/:locale)/users/sign_in(.:format)                                      devise/sessions#new {:locale=>/en|ja/}
                         user_session POST     (/:locale)/users/sign_in(.:format)                                      devise/sessions#create {:locale=>/en|ja/}
                 destroy_user_session DELETE   (/:locale)/users/sign_out(.:format)                                     devise/sessions#destroy {:locale=>/en|ja/}
                        user_password POST     (/:locale)/users/password(.:format)                                     devise/passwords#create {:locale=>/en|ja/}
                    new_user_password GET      (/:locale)/users/password/new(.:format)                                 devise/passwords#new {:locale=>/en|ja/}
                   edit_user_password GET      (/:locale)/users/password/edit(.:format)                                devise/passwords#edit {:locale=>/en|ja/}
                                      PATCH    (/:locale)/users/password(.:format)                                     devise/passwords#update {:locale=>/en|ja/}
                                      PUT      (/:locale)/users/password(.:format)                                     devise/passwords#update {:locale=>/en|ja/}
             cancel_user_registration GET      (/:locale)/users/cancel(.:format)                                       users/registrations#cancel {:locale=>/en|ja/}
                    user_registration POST     (/:locale)/users(.:format)                                              users/registrations#create {:locale=>/en|ja/}
                new_user_registration GET      (/:locale)/users/sign_up(.:format)                                      users/registrations#new {:locale=>/en|ja/}
               edit_user_registration GET      (/:locale)/users/edit(.:format)                                         users/registrations#edit {:locale=>/en|ja/}
                                      PATCH    (/:locale)/users(.:format)                                              users/registrations#update {:locale=>/en|ja/}
                                      PUT      (/:locale)/users(.:format)                                              users/registrations#update {:locale=>/en|ja/}
                                      DELETE   (/:locale)/users(.:format)                                              users/registrations#destroy {:locale=>/en|ja/}
                                      POST     (/:locale)/users/confirmation(.:format)                                 devise/confirmations#create {:locale=>/en|ja/}
                                      GET      (/:locale)/users/confirmation/new(.:format)                             devise/confirmations#new {:locale=>/en|ja/}
                                      GET      (/:locale)/users/confirmation(.:format)                                 devise/confirmations#show {:locale=>/en|ja/}
                                 user GET      (/:locale)/users/:id(.:format)                                          users#show {:locale=>/en|ja/}
                       following_user GET      (/:locale)/users/:id/following(.:format)                                users#following {:locale=>/en|ja/}
                       followers_user GET      (/:locale)/users/:id/followers(.:format)                                users#followers {:locale=>/en|ja/}
                                users GET      (/:locale)/users(.:format)                                              users#index {:locale=>/en|ja/}
                                      POST     (/:locale)/users(.:format)                                              users#create {:locale=>/en|ja/}
                             new_user GET      (/:locale)/users/new(.:format)                                          users#new {:locale=>/en|ja/}
                            edit_user GET      (/:locale)/users/:id/edit(.:format)                                     users#edit {:locale=>/en|ja/}
                                      GET      (/:locale)/users/:id(.:format)                                          users#show {:locale=>/en|ja/}
                                      PATCH    (/:locale)/users/:id(.:format)                                          users#update {:locale=>/en|ja/}
                                      PUT      (/:locale)/users/:id(.:format)                                          users#update {:locale=>/en|ja/}
                                      DELETE   (/:locale)/users/:id(.:format)                                          users#destroy {:locale=>/en|ja/}
                          ahoy_engine          /ahoy                                                                   Ahoy::Engine

इसके अलावा यहाँ मार्ग है.आरबी

  # You can have the root of your site routed with "root"
  # root 'welcome#index'
  get 'home/index'

devise_for :users, skip: [:session, :password, :registration], controllers: { omniauth_callbacks: "users/omniauth_callbacks" }

  #Route for QR
   resources :shortcut, only: [:show]

 # Locale Information
scope "(:locale)", locale: /en|ja/ do
   get '/' => 'frontpage#index'

   resources :knowledge_sprouts
   resources :answers
   resources :reviews
   resources :product_reviews
   resources :relationships, only: [:create, :destroy]

   resources :reviews, :product_reviews, :answers, :knowledge_sprouts do
     resources :upholds, only: [:create, :destroy]
   end

   devise_for :users, skip: [:omniauth_callbacks], :controllers => { :registrations => 'users/registrations' }
   resources :users, :only => [:show]

  devise_scope :users do
    get 'password' => redirect('password/new', status: 301)
  end

   resources :users do
     member do
       get :following, :followers
     end
   end
end
0
Noriaki Takamizawa 24 अगस्त 2017, 04:42

2 जवाब

सबसे पहले, जब आप submit पासवर्ड का प्रदर्शन कर रहे हैं, तो यह create या update क्रिया में जाता है और विधि PATCH या PUT या POST.

हां, आप इसे जबरदस्ती new कार्रवाई पर पुनर्निर्देशित कर सकते हैं (लेकिन यह है एक अच्छा समाधान नहीं है जहाँ तक आपने अपनी समस्या का वर्णन किया है) ओवरराइड करके पासवर्ड नियंत्रक।

यहां आप password_controller को ओवरराइड करने का तरीका ढूंढ सकते हैं।

चियर्स

1
rony36 24 अगस्त 2017, 07:09

ऐसा लगता है कि यह सामान्य रूप से काम करता है। यदि आप अपने मार्गों की जाँच करते हैं और आपको कुछ ऐसा दिखाई देगा:

rake routes | grep password

new_user_password GET      (/:locale)/users/password/new(.:format)       user/passwords#new
    user_password PATCH    (/:locale)/users/password(.:format)           user/passwords#update
                  PUT      (/:locale)/users/password(.:format)           user/passwords#update
                  POST     (/:locale)/users/password(.:format)           user/passwords#create

इसका मतलब है कि http://localhost:3000/en/users/password/new पेज आपके फॉर्म को रेंडर करता है और http://localhost:3000/en/users/password/ वह जगह है जहां फॉर्म डेटा सबमिट करता है।

नोट: यदि आप url दर्ज करके या पृष्ठ पुनः लोड करके http://localhost:3000/en/users/password/ खोलना चाहते हैं, तो आपको GET अनुरोध के लिए राउटर सेटअप करना होगा। आपके वसीयत के दायरे में:

[अद्यतन मार्ग]

scope "(:locale)", locale: /en|ja/ do
  ...

  devise_for :users, skip: [:omniauth_callbacks] , :controllers => { :registrations => 'users/registrations' }
  get 'users/password' => redirect('%{locale}/users/password/new', status: 301)
  resources :users do
    member do
      get :following, :followers
    end
  end

  ...
end

आशा है कि इससे सहायता मिलेगी।

0
hoangdd 28 अगस्त 2017, 06:09
सलाह के लिए धन्यवाद। मुझे नहीं पता था कि यह सामान्य बात है। लेकिन एक बार जब आप url खोलते हैं "localhost:3000/en/users/password", my ऐप इस पते को नहीं खोल सकता। ऐसे में मुझे क्या करना चाहिए? उपरोक्त यूआरएल केवल रीडायरेक्ट लक्ष्य के रूप में काम करता है?
 – 
Noriaki Takamizawa
24 अगस्त 2017, 06:40
मैं अपने उत्तर में एक नोट जोड़ता हूं, आप इसे देख सकते हैं।
 – 
hoangdd
24 अगस्त 2017, 07:55
धन्यवाद। बीटीडब्ल्यू हालांकि मैंने आपकी कॉन्फ़िगरेशन को रूट में लागू किया है, इस तरह त्रुटि आई है। "कोई मार्ग मेल नहीं खाता [पोस्ट] "/ उपयोगकर्ता/पासवर्ड"
 – 
Noriaki Takamizawa
24 अगस्त 2017, 12:45
हम्म, क्या आप rake routes | grep password परिणाम पोस्ट कर सकते हैं। या आप "/ उपयोगकर्ता/पासवर्ड" (नहीं / उपयोगकर्ता s/पासवर्ड) पथ में कौन सा फ़ॉर्म सबमिट कर सकते हैं?
 – 
hoangdd
24 अगस्त 2017, 13:39
मैंने पहले से ही कर लिया। कृपया मेरी प्रश्नावली पर एक नज़र डालें। किसी भी विचार की सराहना की जाती है।
 – 
Noriaki Takamizawa
24 अगस्त 2017, 16:35