質問
historyというメソッドを持つコントローラーがあります
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
users_controller.rb
の履歴メソッドをAjaxで呼び出すにはどうすればよいですか?次の方法で 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:usersは、edit_users_pathを含む多数のurl / 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
所属していません StackOverflow