rails2 如何使用scaffold生成嵌套资源 nesting resource

如下代码可以生成嵌套resources,但是不是很好
     ruby script/generate scaffold post title:string doc:text
     ruby script/generate scaffold comment post:references doc:text
Map.resources :posts :has_many=>:comments

使用gem 生成嵌套资源

https://github.com/chucai/NestedRestfulScaffold

原地址是

https://github.com/mahkhaled/NestedRestfulScaffold

安装
  gem install nested_restful_scaffold

生成嵌套资源

  script/generate nested_restful_scaffold ModelName [field:type, field:type, resource1,resource2,...:resources]


eg:

  script/generate nested_restful_scaffold book name:string description:text library:references library:resources

生成的嵌套资源是

    map.resources :libraries do |library|
      library.resources :books
    end

嵌套资源的URL前加api的方法是

  map.with_options(:path_prefix => "/api") do |api|
    api.resources :circles do |circle|
      circle.resources :activities
    end
  end

会生成 /api/circles/1/activities 的地址



你可能感兴趣的:(rails2 如何使用scaffold生成嵌套资源 nesting resource)