views:

84

answers:

1

i cant understand what the difference is between a namespace and a scope in the routing of ruby-on-rails 3.

could someone please explain?

namespace "admin" do
  resources :posts, :comments
end

scope :module => "admin" do
  resources :posts, :comments
end

thanks

+1  A: 

The different lies in the paths generated.

The paths are admin_posts_path and admin_comments_path for the namespace, while they are just posts_path and comments_path for the scope.

You can get the same result as a namespace by passing the :name_prefix option to scope.

mathepic
by paths u mean the helper names right? i don't understand the scope's functionality. what does it (:module => "admin") do if nothing change?
never_had_a_name
It changes the actual paths used by the route paths to "/admin/whatever", just like namespace. The only different is the prefix added to the helper methods.
mathepic