【问题标题】:Rails3 form_tag routing errorRails3 form_tag 路由错误
【发布时间】:2012-05-03 02:50:24
【问题描述】:

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

我的控制器看起来像:

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 我得到了我的页面,当我点击提交时,我得到了这个错误:

在 2012 年 5 月 2 日星期三 22:38:10 -0400 0:0:0:0:0:0:0:1%0 开始 POST "/account_details/new"

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

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

【问题讨论】:

    标签: ruby-on-rails-3


    【解决方案1】:

    创建新条目的正确方法是 PUT,而不是 POST。你应该从你的模板中删除:method =&gt; "post",所以PUT方法会被自动选择。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-02-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多