2009-10-30 141 views
0

我有有一个方法控制器称为历史路由URL和路径在轨

class UsersController < ApplicationController 

    def history 
    User.return_history(params[:id]) 
    end 

end 

我已经在我的routes.rb文件下列

map.resources :users, :shallow => true do |user| 
    user.resources :friends, :shallow => false 
    user.resources :posts, :collection=>{:no_access => :get} 
    user.resources :photos 
end 

如何尝试Ajax调用users_controller.rb的历史方法?以下列方式

link_to_remote 'History', :url=>history_user_path(@user), :update=>"history", :method=>'get' 

使用link_to_remote扔下我一个错误说history_user_path()没有找到。怎么会这样? edit_user_path()显示没有错误,编辑甚至未在User.rb文件中明确定义。谢谢。

回答

2

mapresources:用户创建一堆url /路径助手方法,包括edit_users_path。如果你需要别人。您必须将其添加为map.resources的:member或collection选项。

这将让你做你想做的:

map.resources :users, :shallow => true, :member => {:history => :get} do |user| 
    user.resources :friends, :shallow => false 
    user.resources :posts, :collection=>{:no_access => :get} 
    user.resources :photos 
end