Ruby on rails rspec中的命名自定义路由

Ruby on rails rspec中的命名自定义路由,ruby-on-rails,ruby-on-rails-3,rspec,routes,Ruby On Rails,Ruby On Rails 3,Rspec,Routes,我正在尝试为我的一个控制器上的自定义操作编写请求规范 My routes.rb是这样的: controller :profile, :path => 'profile' do match 'view_friends/:circle_id', :to => :view_friends, :via => [:get], :as => 'view_friends' end resources :profile 我想参观这次活动,并希望我能使用它 visit profile

我正在尝试为我的一个控制器上的自定义操作编写请求规范

My routes.rb是这样的:

controller :profile, :path => 'profile' do
  match 'view_friends/:circle_id', :to => :view_friends, :via => [:get], :as => 'view_friends'
end
resources :profile
我想参观这次活动,并希望我能使用它

visit profile_path
visit new_profile_path 
etc
我能做到的

visit view_friends_profile_path 
然而,这给了我“错误未定义的局部变量或方法”

我可以通过写作获得想要的行为

visit profile_path.to_s + '/view_friends/' + circle.id.to_s
但这太可怕了。我缺少什么来命名自定义操作

编辑:

rake路由的相关输出

   view_friends GET      (/:locale)/profile/view_friends/:circle_id(.:format)       {:controller=>"profile", :action=>"view_friends"}

首先我有点困惑。通常在rails中,当您创建控制器时,控制器具有复数名称。例如,如果您的模型名为
Profile
,则您将拥有一个
profilescoontroller
。您编写问题的方式意味着您的控制器名为
ProfileController
。似乎有点不寻常,所以如果你能澄清一下,那会很有帮助。也就是说,试试这个:

# in routes.rb
resources :profile do
  member do
    match 'view_friends/:circle_id' => :view_friends, :via => :get, :as => 'view_friends'
  end
end
你应该生产你想要的。您现在可以通过执行以下操作来访问它:

view_friends_profile_path(profile_id, circle_id)

首先我有点困惑。通常在rails中,当您创建控制器时,控制器具有复数名称。例如,如果您的模型名为
Profile
,则您将拥有一个
profilescoontroller
。您编写问题的方式意味着您的控制器名为
ProfileController
。似乎有点不寻常,所以如果你能澄清一下,那会很有帮助。也就是说,试试这个:

# in routes.rb
resources :profile do
  member do
    match 'view_friends/:circle_id' => :view_friends, :via => :get, :as => 'view_friends'
  end
end
你应该生产你想要的。您现在可以通过执行以下操作来访问它:

view_friends_profile_path(profile_id, circle_id)

运行rake路由以确保使用正确的辅助方法。也许您可以将命令的输出添加到问题中。您能够解决问题吗?运行rake routes以确保您使用的是正确的helper方法。也许你可以将命令的输出添加到问题中。你能解决这个问题吗?