Rails form_tag帖子不起作用

时间:2012-11-29 00:15:31

标签: ruby-on-rails ruby-on-rails-3 post

我的users_controller有这些方法

  def follow_code
    @user = current_user
  end

  def followsubmit
    redirect_to root_path
  end

我的路线文件有

  match "follow_code" => "users#follow_code", :as => "follow_code"
  match "follow_code" => 'users#followsubmit', :as => "follow_code", :via => 'post'

我的follow_code.html.erb视图已

<%= form_tag(follow_code_path, :method => 'post') do %>
    <%= submit_tag("Submit") %>
<% end %>

但出于某些原因,当我点击我的视图提交时,我从未被重定向到我的root_path,而是重新呈现了follow_code视图。

我做错了什么?感谢。

1 个答案:

答案 0 :(得分:1)

我也很好奇。我今天遇到了它,也使用了匹配,我的解决方案是重命名后期操作:

 match "follow_code" => "users#follow_code", :as => "follow_code"
 match "save_follow_code" => 'users#followsubmit', :as => "save_follow_code", :via => 'post'

但是,我使用condition属性来指定方法。在您的情况下,您可能只需要将第一个指定为get。

match "follow_code" => "users#follow_code", :as => "follow_code", :via => 'get'
match "follow_code" => 'users#followsubmit', :as => "follow_code", :via => 'post'