I’m trying to write a request spec for a custom action on one of my controllers.
My routes.rb is like this:
controller :profile, :path => 'profile' do
match 'view_friends/:circle_id', :to => :view_friends, :via => [:get], :as => 'view_friends'
end
resources :profile
I want to visit this action, and was hoping that as I can use
visit profile_path
visit new_profile_path
etc
That I could do
visit view_friends_profile_path
However this gives me the “error undefined local variable or method “
I can get the desired behavior by writing
visit profile_path.to_s + '/view_friends/' + circle.id.to_s
But that is horrible. What am I missing to be able to name a custom action?
edit:
Relevant output from rake routes
view_friends GET (/:locale)/profile/view_friends/:circle_id(.:format) {:controller=>"profile", :action=>"view_friends"}
Firstly I’m a bit confused. Usually in rails when you make a controller, the controller has a plural name. For instance if your model name is
Profile, then you would have aProfilesController. The way you are writing your question implies that your controller is namedProfileController. Seems kind of unusual, so if you could clarify that would be helpful. That being said, try this:Should produce what you want. You can access it now by doing this: