Question

I'm working on creating an app that allows users to create surveys. I decided to add in the rapidfire gem which really helps to speed up the process of making surveys.

So far it's working great, however the "Home" link in my head that points to the root_url no longer brings me back to the root, but the "rapidfire" homepage.

Here's my config/routes.rb file:

 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"

when I do rake routes I get this:

 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

I guess I don't really understanding what the "mount Rapidfire::Engine => "/surveys"" line is doing. Is there anyway I can adjust the root that it's generating so that it indeed points back to my original app's home page?

Was it helpful?

Solution

RapidFire, as an engine, has it's own root which is mounted under the /surveys path that you specified. Calling root_path from within a RapidFire namespaced controller/view will refer to the that root - not the sitewide root.

To fix this, you can pass the sitewide root path to the engine, and call that from the header instead - see Rails.root from engine for a way to do this.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top