Reputation: 2638
My users_controller has these methods
def follow_code
@user = current_user
end
def followsubmit
redirect_to root_path
end
My route file has
match "follow_code" => "users#follow_code", :as => "follow_code"
match "follow_code" => 'users#followsubmit', :as => "follow_code", :via => 'post'
My follow_code.html.erb view has
<%= form_tag(follow_code_path, :method => 'post') do %>
<%= submit_tag("Submit") %>
<% end %>
Yet for some reason when I click submit on my view I am never redirected to my root_path and instead the follow_code view is re-rendered.
What am I doing wrong? Thanks.
Upvotes: 0
Views: 122
Reputation: 6810
I'm also curious about this. I ran into it today, using match as well, and my solution was to rename the post action:
match "follow_code" => "users#follow_code", :as => "follow_code"
match "save_follow_code" => 'users#followsubmit', :as => "save_follow_code", :via => 'post'
However, I was using the condition attribute to specify the method. In your case, you may just need to specify the first one as a get.
match "follow_code" => "users#follow_code", :as => "follow_code", :via => 'get'
match "follow_code" => 'users#followsubmit', :as => "follow_code", :via => 'post'
Upvotes: 1