Search code examples
ruby-on-railsrubycrudrestful-architecture

Best practice for further actions in rails controllers


i'm just writing my first app in rails and i wonder, if there is a best practice to do the following:

i have a customer model created by a scaffold and pumping it up. a customer has to be displayed in a google map, so if go to /customers/23, the customer information are displayed. additionally i have a link within this page to show the user in a map (with a query ui dialog that comes up via ajax). The question for me is, how does this fits in the normal crud structure of the model. Should i do like creating an action, called "show_map" and give it an extra route additionally to the resources routes? How do you handle this kind of things?


Solution

  • Lets do it like

    resources :customers do
     resource :map, :only => [:index]
    end
    

    it will generate routes like this

    {:action=>"show", :controller=>"maps"}     customer_map GET      /customers/:customer_id/map(.:format)