Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
569 views
in Technique[技术] by (71.8m points)

difference between scope and namespace of ruby-on-rails 3 routing

I can't 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
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The difference 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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...