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
When using a has_one
, it might make sense to declare it as a singular resource in your routes. Meaning
resources :users do
resource :about # notice "resource" and not "resources"
end
And if you want to override the paths for new/edit, add a :path_names
option to the resource/resources-call:
resources :about, :path_names => { :new => 'add', :edit => 'edit' }
The official documentation has lots of other tips and tricks for routing as well.
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"}