Handling has_one nested resource in Rails 3

前端 未结 2 1832
死守一世寂寞
死守一世寂寞 2021-01-20 02:22

I got a User model and a About model. The about model is a page where users have more info about them that due its nature is more appropriate to have it on a separate model

2条回答
  •  说谎
    说谎 (楼主)
    2021-01-20 03:05

    You can use scope and controller blocks to cut down on the verbiage:

      scope "/:username" do
        controller :abouts do
          get 'about' => :show
          post 'about' => :create
          get 'about/add' => :new
          get 'about/edit' => :edit
        end
      end
    

    which produces:

         about GET /:username/about(.:format) {:action=>"show", :controller=>"abouts"}
               POST /:username/about(.:format) {:action=>"create", :controller=>"abouts"}
     about_add GET /:username/about/add(.:format) {:controller=>"abouts", :action=>"new"}
    about_edit GET /:username/about/edit(.:format) {:controller=>"abouts", :action=>"edit"}
    

提交回复
热议问题