Rails3 form_tag路由错误

时间:2012-05-03 02:50:25

标签: ruby-on-rails-3

我无法让视图和控制器一起玩得很好。我想我搞砸了我的路线,任何帮助都会很棒。

我的控制器如下:

class AccountDetailsController < ApplicationController

    def new
      puts "in new"
    end

    def home
      puts "in home"
    end
end

我的routes.rb看起来像:

resources :account_details

我的new.html.erb看起来像:

<h1>AccountDetails#new</h1>
<%= form_tag(url_for(:controller => "account_details", :action => "new"), :method => "post") do %>
  <%= label_tag(:q, "Search for:") %>
  <%= text_field_tag(:q) %>
  <%= submit_tag("Submit") %>
<% end %>

当我转到http://localhost:3000/account_details/new时 我得到了我的页面,当我点击提交时,我收到此错误:

开始POST“/ account_details / new”为0:0:0:0:0:0:0:1%0于5月2日星期三22:38:10 -0400 2012

ActionController :: RoutingError(没有路由匹配[POST]“/ account_details / new”):

除了无能为力外,我做错了什么?我以为我的路线会覆盖[POST],不是吗?

1 个答案:

答案 0 :(得分:0)

创建新条目的正确方法是PUT,而不是POST。您应该从模板中删除:method => "post",因此将自动选择PUT方法。

相关问题