user1743476
user1743476

Reputation:

Rails: Using Links to pass POST parameters

    <%= link_to "Follow", { :controller => "friendship", :action => "follow",:id=> friend.id} , :remote => true, :class => "follow_user" %>
  1. How do I use 'links' to pass argument 'id' as a POST variable and not as a parameter in the URL?
  2. And then, How do I make 'follow' action in 'friendship' controller only accept POST variable so that nobody can use 'http://localhost:3000/friendship/follow?id=8' in the URL to perform the action?

Upvotes: 0

Views: 577

Answers (2)

m_x
m_x

Reputation: 12564

  1. Add method: :post to your link_to options.
  2. Use a constraint on your route, or check if request is POST with request.post?in your controller.

Upvotes: 0

tdgs
tdgs

Reputation: 1096

Try <%= button_to "Follow", { controller: "friendship", action: "follow", id: friend.id}, remote: true, class: "follow_user", method: :post %>

Upvotes: 1

Related Questions