0

我的简单表格不是在做 POST。我一直在看这个,但看不出有什么问题(我确定它在我的路线中)。这是我所拥有的:

看法:

views/buyers/new.html.erb

    <%= form_for(@buyer) do |f| %>
            <%= f.text_field :phone %><br />
            <%= f.text_field :make %><br />
            <%= f.text_field :model %><br />
            <%= f.submit %>
          <% end %>

控制器:

BuyersController
  def new
    @title = "Welcome to Car Finder"
    @buyer = Buyer.new
  end 

  def create
    @buyer = Buyer.new(params[:buyer])
    if @buyer.save!
      redirect_to success
    else
      redirect_to :back
    end
   end

路线:

resources :buyers 

耙路线:

                    buyers GET    /buyers(.:format)                buyers#index
                           POST   /buyers(.:format)                buyers#create
                 new_buyer GET    /buyers/new(.:format)            buyers#new
                edit_buyer GET    /buyers/:id/edit(.:format)       buyers#edit
                     buyer GET    /buyers/:id(.:format)            buyers#show
                           PUT    /buyers/:id(.:format)            buyers#update
                           DELETE /buyers/:id(.:format)            buyers#destroy

当我提交表单时,它停留在同一页面上,永远不会进入创建操作。以下来自日志

Started GET "/?..[params]..."
Processing by BuyersController#new as HTML

谢谢你提供的所有帮助

4

1 回答 1

0

重新启动服务器可能是明智之举。您的问题可能在于您在持久性级别或buyer.rb文件中的验证。将此添加到 _form.html.erb:

<% if @buyer.errors.any? %>
 <div id="error_explanation">
  <h2><%= pluralize(@buyer.errors.count, "error") %> prohibited this from being saved:   </h2>

  <ul>
  <% @buyer.errors.full_messages.each do |msg| %>
    <li><%= msg %></li>
  <% end %>
  </ul>
 </div>
<% end %>

尝试再次完成请求。看看是否有任何错误被抛出。修复那些。

于 2012-09-14T18:53:02.737 回答