Custom Rest actions

I am trying to create a friendship and I created a custom action called accept. however i can't reach it. Everytime I call it i get the action show could not be found.

Here my route.rb file

  resources :friendships do
    collection do
      delete 'cancel'
      get 'accept'
    end
  end

Here how i call it

<%= link_to 'Accept', accept_friendships_path(:friend_id => f) %>

accept_friendships was taken from rake routes commands. And here how i define my accept controller

  #Accept friendships
  def accept
    if @customer.requested_friends.include?(@friend)
      Friendship.accept(@customer, @friend)
      flash[:notice] = "Friendship Accepted"
    else
      flash[:notice] = "No Friendship request"
    end
    redirect_to root_url
  end

Here the error

Unknown action

The action 'show' could not be found for FriendshipsController

Answers


Maybe I am wrong, but why you want "accept" to be a collection? I guess you want it to be a member, since you are passing friend_id. If you change it to member and make the path accept_friendship_path(@friendship) [ note singular form of friendship ], you might have better luck. Beside an addition argument your case does not differ from example on Ruby on Rails Guides, that is why it is worth to try it


Need Your Help

User security stamp for Active Directory

c# asp.net-mvc active-directory ldap asp.net-identity

I have a Multitenant MVC5 application which lets tenants specify their authentication &amp; authorisation method. They can choose between local account which uses ASPIdentity behind the scenes or u...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.