简体   繁体   English

在Rails 3.2中的devise用户下生成脚手架

[英]generate scaffold under devise user in rails 3.2

I use devise, and I want generate a new object scaffold under devise user sth like: 我使用devise,我想在devise用户下生成一个新的对象支架:

 resources :users, :path => "/", :only => [:show] do
   resources :collections, :controller => 'users/collections'
 end

With above routes, I get this url: 通过以上路线,我得到以下网址:

http://localhost:3000/kevin_doe/collections

The problem is that if I issue this command: 问题是,如果我发出以下命令:

rails g scaffold users/collection title:string description:text

This generate a namespace sth like: 这样会生成一个名称空间:

namespace :users do resources :collections end

The route that I get is: 我得到的路线是:

http://localhost:3000/users/collections

I want generate a scaffold under devise user resource. 我想在设计用户资源下生成一个脚手架。

How can I fix this problem? 我该如何解决这个问题?

Thank you! 谢谢!

The fix for this question are the next steps: 此问题的解决方法是以下步骤:

1º generate the scaffold with: 1º用以下方法生成支架:

rails g scaffold collection title:string description:text

2º Modify your routes.rb file with the nested resource: 2º使用嵌套资源修改您的routes.rb文件:

resources :users, :path => "/", :only => [:show] do
   resources :collections, :controller => 'users/collections'
 end

3º you must create a "users" folder in your controllers directory and move the collections_controller.rb to 3º您必须在控制器目录中创建一个"users" folder ,并将collections_controller.rb移至

app/controllers/users/

4º in collections_controller.rb you must modify: 您必须在collections_controller.rb 4º修改:

class Users::CollectionsController < ApplicationController
.
.
.
end

5º In your views you must move the folder collections to app/views/users/collections 5º在您的视图中,您必须将文件夹collections移动到app/views/users/collections

Done! 完成! :D. :D

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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