Ruby on rails 同一资源存在问题,可通过两条路径访问
我正在开发一个简单的图像共享站点来训练我的RubyonRails。我的Ruby on rails 同一资源存在问题,可通过两条路径访问,ruby-on-rails,rest,rails-routing,Ruby On Rails,Rest,Rails Routing,我正在开发一个简单的图像共享站点来训练我的RubyonRails。我的config/routes.rb文件中有以下资源 resources :users do resources :images end resources :images 我面临的问题是——我应该如何实现“最新图像”和“您的图像订阅”等功能?有了香草资源url,现在看起来是这样的: /users/N/images # ImagesController#index action for listing all images
config/routes.rb
文件中有以下资源
resources :users do
resources :images
end
resources :images
我面临的问题是——我应该如何实现“最新图像”和“您的图像订阅”等功能?有了香草资源url,现在看起来是这样的:
/users/N/images # ImagesController#index action for listing all images for a user
/images # ImagesController#index action for listing all possible images from all users.
在images controller中访问索引操作时,您将如何管理图像的“父”对象?在
params
散列中简单地检查:user_id
就足够了吗?有没有我不知道的插件(因为我想不出这个问题的简单描述)。我会将一个插件分配给另一个控制器,这样你就不会混淆它们,混淆自己
resources :users do
resources :images, :controller => user_images
end
resources :images
现在在
UserImagesController
before_filter :get_user
def get_user
@user = User.find(params[:id])
// You could also do error checking in before_filters
end