Tuesday 13 December 2011

Leonardo: update to version 1.9

I just released the1.9 version which enhances and completes the resources management.



If you use the --under option to nest the new resource under another existing one, must be edited the file config / routes.rb because the operation will create the new routes nested, overwriting the originals.


For example if we create the product resource, leonardo will create these routes:
resources :products do
  post :select,           :on => :collection
  post :edit_multiple,    :on => :collection
  put  :update_multiple,  :on => :collection
  put  :create_multiple,  :on => :collection
end

if then we create the comment resource under product you will get:
resources :products do
  resources :comments do
    post :select,           :on => :collection
    post :edit_multiple,    :on => :collection
    put  :update_multiple,  :on => :collection
    put  :create_multiple,  :on => :collection
  end
end

resources :products do
  post :select,           :on => :collection
  post :edit_multiple,    :on => :collection
  put  :update_multiple,  :on => :collection
  put  :create_multiple,  :on => :collection
end

but you have to join it to get something like this:
resources :products do
  post :select,           :on => :collection
  post :edit_multiple,    :on => :collection
  put  :update_multiple,  :on => :collection
  put  :create_multiple,  :on => :collection
  resources :comments do
    post :select,           :on => :collection
    post :edit_multiple,    :on => :collection
    put  :update_multiple,  :on => :collection
    put  :create_multiple,  :on => :collection
  end
end
Moreover, the list of resources shows a link to the nested resource for the parent who uses the name field. If not present you should replace it with some other field otherwise you can add the method name into the model:
class Product < ActiveRecord::Base

  def name
    self.title
  end
end

No comments:

Post a Comment