2015-09-05 64 views
0

Rails的默認本地主機:3000映射到welcome_controller#索引頁,我想使用我的自定義登陸頁面的根。我也使用設計進行身份驗證設置。Rails本地主機自定義登陸頁面與設計

當我給本地主機:3000設計自動重定向到本地主機:3000 /用戶/ sign_in。

如何更改自定義頁面的根目錄以及放置index.html文件的位置,以便可以看到目標頁面。

+0

瑪尼,試試我的答案,讓我知道你是否有任何問題。 –

回答

0

您可以添加到您的routes.rb文件的頂部:

get "/" => "custom_controller#custom_action", as: :custom_root_path 

,這將給你這條路線:

custom_root_path GET / custom_controller#custom_action 

然後,你可以把你的自定義目標網頁的內容在相應的視圖(custom_action.html.erb文件)中的custom_controllercustom_action

例如,如果你的名字你定製的控制器landing_pages_controller,動作index,那麼路徑將是:

get "/" => "landing_pages#index", as: :custom_root_path 

然後,你將有一個index方法在landing_pages_controller.rb文件,將有一個app/views/landing_pages/index.html.erb文件,您可以在其中放置自定義着陸頁的內容。

+0

我用index.html.erb文件創建了welcome_controller.rb。在我的應用程序中,我爲佈局創建了一些頁眉和頁腳,因爲我使用了current_user,所以此index.html.erb使用應用程序佈局給出錯誤bcz,但我不想包含着陸頁的佈局 –

+0

只需創建另一個方法'landing_page',然後創建一個相應的視圖:'landing_page.html.erb'並在那裏放置您的自定義着陸頁內容。在這種情況下,路由將是:'get「/」=>「welcome_controller#landing_page' –

+0

@ManiDavid讓我知道它是否適合您或者您有任何其他問題。 –