使用Rapidfire进行Rails路由

时间:2014-01-27 20:46:18

标签: ruby-on-rails gem rails-routing

我正在努力创建一个允许用户创建调查的应用。我决定加入rapidfire gem,它真的有助于加快调查过程。

到目前为止,它工作得很好,但是我脑海中指向root_url的“Home”链接不再让我回到root,而是“rapidfire”主页。

这是我的config / routes.rb文件:

 SurveyMe::Application.routes.draw do
 devise_for :developers
 devise_for :users
 mount Rapidfire::Engine => "/surveys"
 root "static_pages#home"
 match "/about", to: "static_pages#use", via: "get"
 match "/developers", to: "static_pages#developer" , via: "get"
 match "/how", to: "static_pages#how", via: "get"

当我做rake路线时,我得到了这个:

 rapidfire        /surveys                            Rapidfire::Engine
                     root GET    /                                   static_pages#home
                    about GET    /about(.:format)                    static_pages#use
               developers GET    /developers(.:format)               static_pages#developer
                      how GET    /how(.:format)                      static_pages#how

 Routes for Rapidfire::Engine:
     results_question_group GET    /question_groups/:id/results(.:format)                           rapidfire/question_groups#results
   question_group_questions GET    /question_groups/:question_group_id/questions(.:format)          rapidfire/questions#index
                            POST   /question_groups/:question_group_id/questions(.:format)          rapidfire/questions#create
     new_question_group_question GET    /question_groups/:question_group_id/questions/new(.:format)      rapidfire/questions#new
    edit_question_group_question GET    /question_groups/:question_group_id/questions/:id/edit(.:format) rapidfire/questions#edit
         question_group_question GET    /question_groups/:question_group_id/questions/:id(.:format)      rapidfire/questions#show
                            PATCH  /question_groups/:question_group_id/questions/:id(.:format)      rapidfire/questions#update
                            PUT    /question_groups/:question_group_id/questions/:id(.:format)      rapidfire/questions#update
                            DELETE /question_groups/:question_group_id/questions/:id(.:format)      rapidfire/questions#destroy
    question_group_answer_groups POST   /question_groups/:question_group_id/answer_groups(.:format)      rapidfire/answer_groups#create
    new_question_group_answer_group GET    /question_groups/:question_group_id/answer_groups/new(.:format)  rapidfire/answer_groups#new
                 question_groups GET    /question_groups(.:format)                                       rapidfire/question_groups#index
                            POST   /question_groups(.:format)                                              rapidfire/question_groups#create
         new_question_group GET    /question_groups/new(.:format)                                   rapidfire/question_groups#new
        edit_question_group GET    /question_groups/:id/edit(.:format)                              rapidfire/question_groups#edit
             question_group GET    /question_groups/:id(.:format)                                   rapidfire/question_groups#show
                            PATCH  /question_groups/:id(.:format)                                   rapidfire/question_groups#update
                            PUT    /question_groups/:id(.:format)                                   rapidfire/question_groups#update
                            DELETE /question_groups/:id(.:format)                                   rapidfire/question_groups#destroy
                       root GET    /                                                                       rapidfire/question_groups#index

我想我并不真正理解“mount Rapidfire :: Engine =>”/调查“”行正在做什么。无论如何,我可以调整它生成的根,以便它确实指向我原来的应用程序的主页?

1 个答案:

答案 0 :(得分:0)

RapidFire作为引擎,拥有自己的root,它安装在您指定的/surveys路径下。从RapidFire命名空间控制器/视图中调用root_path将引用该根 - 而不是站点范围的根。

要解决此问题,您可以将网站范围的根路径传递给引擎,然后从标题中调用该路径 - 请参阅Rails.root from engine以获取执行此操作的方法。