我有一個表單名稱(反饋),我試圖提交它。HAML rails form_for不調用POST方法
但是,它一直在調用GET HTTP方法。我已經嘗試爲form_for參數添加:method =>:post,但它仍然不起作用。我能知道它爲什麼不調用POST方法嗎?
耙路線:
Prefix Verb URI Pattern Controller#Action
feedbacks POST /feedback(.:format) feedbacks#create
new_feedback GET /feedback/new(.:format) feedbacks#new
root GET/ welcome#index
FeedbacksController
class FeedbacksController < ApplicationController
def create
@feedback = Feedback.new(feedback_params)
@feedback.save
end
def new
@feedback = Feedback.new
end
private
def feedback_params
# params.require(:feedback).permit(: )
end
end
反饋/ new.html.haml
.container.col-xs-12.col-sm-8.col-sm-offset-2.col-md-8.col-md-offset-2.col-lg-8.col-lg-offset-2
.WhiteSpace
=fa_icon "coffee 2x"
=fa_icon "coffee 2x"
=fa_icon "coffee 2x"
%h4 Help us serve you better by telling us what you think !
.WhiteSpace
%form.form-horizontal
=form_for(@feedback, :method => :post) do |feedback|
.form-group
%feedback.label_field.col-sm-2.control-label <b>Name</b>
.col-sm-6
=feedback.text_field(:name, :class =>"form-control" ,:placeholder => "Name")
.form-group
%feedback.label_field.col-sm-2.control-label <b>Email (optional)</b>
.col-sm-6
=feedback.text_field(:email, :class => "form-control", :placeholder => "Email")
.form-group
%feedback.label_field.col-sm-2.control-label <b>Tel No. (optional)</b>
.col-sm-6
=feedback.text_field(:telephone_no, :class => "form-control", :placeholder =>"Telephone No.")
-#TODO: Use Ratyrate
.form-group
%h3.col-sm-2.control-label!="<u>Services</u>"
.form-group
%feedback.label_field.col-sm-2.control-label <b>Delivery</b> :
.col-sm-6
=fa_icon "star-o 2x"
=fa_icon "star-o 2x"
=fa_icon "star-o 2x"
=fa_icon "star-o 2x"
=fa_icon "star-o 2x"
.form-group
%feedback.label_field.col-sm-2.control-label <b>Friendliness</b> :
.col-sm-6
=fa_icon "star-o 2x"
=fa_icon "star-o 2x"
=fa_icon "star-o 2x"
=fa_icon "star-o 2x"
=fa_icon "star-o 2x"
.form-group
%feedback.label_field.col-sm-2.control-label <b>Price </b>:
.col-sm-6
=fa_icon "star-o 2x"
=fa_icon "star-o 2x"
=fa_icon "star-o 2x"
=fa_icon "star-o 2x"
=fa_icon "star-o 2x"
.form-group
%feedback.label_field.col-sm-2.control-label <b>Message:</b>
.col-sm-6
=feedback.text_area(:comment, :class => "form-control", :placeholder=> "Comment",:rows =>"10")
.form-group
=feedback.submit("Submit", :class =>"btn-primary btn-lg btn-block")
而不是':method =>:post',嘗試'url:{action:「create」}' – fanta