您的位置:首页 > 大数据 > 人工智能

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

2012-05-04 17:17 232 查看
如下代码可以生成嵌套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 的地址
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: