我有3个视图,使用创建表单,但示例def def def创建效果很好,但其他def不起作用...
class RateFormController < ApplicationController
def new
@rateform = RateForm.new
end
def create
@rateform = RateForm.new(rate_params)
if @rateform.save
redirect_to :root
RateFormMailer.rate_email(@rateform).deliver_now
end
end
def encreate
@rateform = RateForm.new(rate_params)
RateFormMailer.rate_email(@rateform).deliver_now
# ContactsMailer.sample_email(@contact).deliver_now
end
def rucreate
@rateform = RateForm.new(rate_params)
if @rateform.save
redirect_to :root
RateFormMailer.rate_email(@rateform).deliver_now
end
end
private
def rate_params
params.require(:rate_form).permit(:name, :mail, :comment, :ratename, :phone)
end
end
RateFormController中的ActionController :: ParameterMissing #encreate param丢失或值为空:rate_form
答案 0 :(得分:0)
只需在routes.rb
文件
resources :rate_forms do
get :encreate
get :rucreate
end
答案 1 :(得分:0)
我认为它们是空的,因为你正在使用GET
方法
rate_form_encreate_path GET /rate_form/encreate(.:format) rate_form#encreate
rate_form_rucreate_path GET /rate_form/rucreate(.:format) rate_form#rucreate
这些是GET
类型
请将其更改为POST
类型。
match '/rate_form/encreate' => 'rate_form#encreate', via: [:post], :as => :rate_form_encreate
match '/rate_form/rucreate' => 'rate_form#rucreate', via: [:post], :as => :rate_form_rucreate
更新:
match '/rate_form/ennew' => 'rate_form#ennew', via: [:get], :as => :rate_form_ennew
match '/rate_form/runew' => 'rate_form#runew', via: [:get], :as => :rate_form_ennew