1

以下是我的應用程序的路徑:如何添加一個名爲幫手控制器Rails的

[email protected]:~/HelloWorld$ rake routes 
     Prefix Verb URI Pattern    Controller#Action 
biodata_store GET /biodata/store(.:format) biodata#store 
greet_welcome GET /greet/welcome(.:format) greet#welcome 
greet_wishes GET /greet/wishes(.:format) greet#wishes 
    time_htime GET /time/htime(.:format) time#htime 
    login_auth POST /login/auth(.:format) login#auth 
       POST /biodata/store(.:format) biodata#store 
     greet GET /greet(.:format)   greet#index 
     time GET /time(.:format)   time#index 
     login GET /login(.:format)   login#index 
     biodata GET /biodata(.:format)  biodata#index 
[email protected]:~/HelloWorld$ 

在上面的路線,我有一個名爲「登錄」控制器。所以當我調用'localhost:3000/login'時,它會提供'index.html'文件,其中 被放置在'app/view/login /'目錄中。一旦我提交登錄表單,輸入的數據將轉到「/ login/auth」操作。在這裏,我將 設置爲index.html文件中的POST方法。所以,我只能直接從瀏覽器獲取'/ login'而不是'/ login/auth'頁面。

與此類似,我創建了一個'/ biodata'控制器,它提供輸入表單以獲取用戶的詳細信息。一旦我提交表格, 數據將通過POST方法傳遞給'/ biodata/store'。所以,我希望我無法直接從 瀏覽器訪問'/ biodata/store'控制器。但在我的應用程序中,我可以訪問它。如何解決這個問題呢 ?

/login --> User can access directly. 
    /login/auth --> User should not access this page directly. 

如上所述登錄控制器正常工作。但是下面的biodata控制器工作不正常。

/biodata --> User can access directly. 
    /biodata/store --> User should not access this page directly.(But now it is accessible). 

我希望這是由於命名助手。因爲控制器/生物數據/存儲區沒有名稱助手中的條目。那麼如何解決這個問題呢?

的routes.rb:

Rails.application.routes.draw do 
    get 'biodata/store' 
    get 'greet/welcome' 
    get 'greet/wishes' 
    get 'time/htime' 
    post 'login/auth' 
    post 'biodata/store' 
    get 'greet' => 'greet#index' 
    get 'time' => 'time#index' 
    get 'login' => 'login#index' 
    get 'biodata' => 'biodata#index' 
end 
+0

你可以發送你的路線文件? –

+1

剛剛刪除GET/biodata/store –

+0

@TonyVincent感謝您的幫助。我忘記看到了。 – mrg

回答

3

用戶可以因爲你在你的routes.rb一個

get 'biodata/store' 

路線直接訪問該頁面。剛剛刪除,你會很好去

相關問題