简体   繁体   中英

Ruby on rails path helpers

I know this is a minor issue, but why, if you use scaffolding in RoR, can you use lines like 'new_ model name here _path' in link tags, but without using scaffolding, I get a NameError? For example, I have a simple address book app that uses basic CRUD operations. I am a RoR beginner but wanted to build an app without scaffolding and these kind of things don't seem to work. I compared my config/routes.rb and app/helpers/* with those in a scaffolded app and they are no different. What am I missing?

One way to check your routes and paths is to run:

rake routes

It outputs all your routes and paths.

Scaffolding sets up resource routes in the routes.rb file. The resource routes are what give you the path and url helpers. When you don't use scaffolding the routes aren't added, you must do it by hand.

Resource Routes can be added like so:

map.resources :models

where :models is the plural name of one of your models.

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