views:

54

answers:

1

I have a controller which has a method called history

class UsersController < ApplicationController

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

end

I have the following in my routes.rb file

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

How do I try to Ajax call the history method of the users_controller.rb? Using link_to_remote in the following way

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

throws me an error saying history_user_path() not found. How can this be? edit_user_path() shows no error and edit is not even explicitly defined in the User.rb file. Thanks.

+2  A: 

mapresources :users creates a bunch of url/path helper methods, including edit_users_path. If you need others. you've got to add it as either a :member, or :collection option for map.resources.

This will let you do what you want:

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
EmFi