Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7877891
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T03:30:27+00:00 2026-06-03T03:30:27+00:00

I know how to do this with match but I really want to do

  • 0

I know how to do this with match but I really want to do it in the resource block. Here’s what I have (simplified):

resources :stories do
  member do
    'put' collaborator
    'delete' collaborator
  end
end

I am looking for a way to allow the same action name in the URL but have different entry points in the controller. At the moment I’ve got in my controller:

# PUT /stories/1/collaborator.json
def add_collaborator
  ...
end

# DELETE /stories/1/collaborator.json
def remove_collaborator
  ...
end

So I tried this:

resources :stories do
  member do
    'put' collaborator, :action => 'add_collaborator'
    'delete' collaborator, :action => 'remove_collaborator'
  end
end

but this didn’t seem to work when I wrote an rspec unit test:

describe "PUT /stories/1/collaborator.json" do
  it "adds a collaborator to the story" do
    story = FactoryGirl.create :story
    collaborator = FactoryGirl.create :user

    xhr :put, :collaborator, :id => story.id, :collaborator_id => collaborator.id

    # shoulds go here...
end

end

I get this error:

Finished in 0.23594 seconds
5 examples, 1 failure, 1 pending

Failed examples:

rspec ./spec/controllers/stories_controller_spec.rb:78 # StoriesController PUT    
  /stories/1/collaborator.json adds a collaborator to the story

I’m assuming this error is because the way I’m trying to define my routes is incorrect…any suggestions?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T03:30:28+00:00Added an answer on June 3, 2026 at 3:30 am

    Is the following better?

    resources :stories do
     member do
       put 'collaborator' => 'controller_name#add_collaborator' 
       delete 'collaborator' => 'controller_name#remove_collaborator'
     end
    end
    

    You should also check your routes by launching in a terminal:

    $ rake routes > routes.txt
    

    And opening the generated routes.txt file to see what routes are generated from your routes.rb file.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know this is an old question, but I have spend any hours on
I don't really know what to entitle this, but I need some help with
I know this may seem like a math question but i just saw this
Know this might be rather basic, but I been trying to figure out how
i know this is a stupid question but i d'ont know how to do
I know this is possible in Perl, but I was wondering if this can
I know this is probably something simple but I can't seem to find anything
I know this is repeated question on Stack. But in my case the URL
i have strings in the form [abc].[some other string].[can.also.contain.periods].[our match] i now want to
I am not a very good coder. But I really want to automate something

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.