简体   繁体   中英

ROR: Routes issue - Survey gem

The Survey gem is not creating the routes on my Rails app so I am wondering what to put in the routes.rb file?

I ran

 rails generate survey:install

then ran

rails generate survey routes namespace:survey

and does not work.

I'm using Rails 4.2.1

The controllers are at controllers/survey/attempts_controller.rb and controllers/survey/surveys_controller.rb

The views are at survey/attempts/ and survey/surveys/

How should I put in the routes for these? Thanks.

Survey uses a standard CRUD interface, so you should be able to add resources named after the survey model you've created.

ie resources :surveys

If this doesn't do the trick, you can see a basic routing setup in the survey demo app here: https://github.com/runtimerevolution/survey-demo/blob/master/config/routes.rb

Let me know if this helps!

Its okay if it didn't add routes to your routes.rb file. You can add it yourself. And since you have it namespaced within Survey for your controllers you have to namespace in your routes file too.

namespace :survey do
  resources :surveys
  resources :attempts
  get 'survey_details' => 'surveys#get_details' #this request will be handled by get_details method of SurveysController
end

Since it uses basic Create Read Update Delete in its controller, resources :surveys will take care of these. For any additional routes you want to define for your controllers make sure to put them inside the namespace block.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM