0
我的简单表单未执行POST。我一直在看这个,一直没有看到什么是错的(我确定它在我的路线中)。下面是我有:Rails创建操作不起作用
观点:
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
感谢您的帮助,您可以给
您在买方控制器中的创建动作如何?请分享。 – rhodee
你在表单提交时会出现什么错误? –
对不起,我更新了这个问题。我没有收到错误。它只是将参数添加到URL并保持在同一页面 – user1524775