param丢失或值为空rails controller

时间:2016-06-16 11:54:40

标签: ruby-on-rails ruby

我有3个视图,使用创建表单,但示例def def def创建效果很好,但其他def不起作用...

RateFormController.rb

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

127.0.0.1:3000/rate_form/encreate

  

RateFormController中的ActionController :: ParameterMissing #encreate      param丢失或值为空:rate_form

2 个答案:

答案 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