Search code examples
ruby-on-rails-3postactionmailercsrf

Submit form from e-mail rails 3


I have an action which sends info to the serve through a POST method and I want it to be trigger from an email through a link.

I'v tried this in my email template:

First, specify the post method in a link_to tag:

<%= link_to 'click here', action_url(:id => @model.id), :method => 'post' %>

but the action is triggered with a GET method and I get a routing error.

And second, do it through a form with a hidden field but the csrf token was not recognized:

<%= form_tag action_url, :method => 'post' do %>
    <%= hidden_field_tag :id, @model.id %>
    <%= submit_tag 'click here' %>
<% end %>

Is there anyway to do this? Or if there isn't, what's my best option?


Solution

  • Couldn't make the post request, so just add the get route for the action.

    Positive part: Worked fine, not complications

    Negative part: Had to implement some before_filter methods for security due the parameters were passed through the URL