我有有一个方法称为历史控制器

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

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

我抛出找不到一个错误说history_user_path()。怎么会这样? edit_user_path()显示没有错误,编辑甚至没有明确的User.rb文件中定义。感谢。

有帮助吗?

解决方案

mapresources:用户创建一堆URL /路径的辅助方法,包括edit_users_path。如果你需要别人。你必须将其添加为无论是:成员,或:集合map.resources选项。

这将让你做你想做的:

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
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top