The Error I Get參數是丟失或爲空值:subscribeduser
我得到的錯誤,當我試圖通過轉換params.require(:subscribeduser).permit(:email)
到params.permit(:email)
創建一個新的subscribeduser
,我有點「固定」的,但我覺得不舒服關於它。我如何正確擺脫這個錯誤?
SubscribedusersController
class SubscribedusersController < ApplicationController
before_action :set_subscribeduser, only: [:show, :edit, :update, :destroy]
def index
@subscribedusers = Subscribeduser.all
end
def new
@subscribeduser = Subscribeduser.new
end
def create
@subscribeduser = Subscribeduser.new(subscribeduser_params)
respond_to do |format|
if @subscribeduser.save
RegistrationMailer.thankyou_mail(@subscribeduser).deliver_now
format.html { redirect_to @subscribeduser, notice: 'Subscribeduser was successfully created.' }
format.json { render :show, status: :created, location: @subscribeduser }
else
format.html { render :new }
format.json { render json: @subscribeduser.errors, status: :unprocessable_entity }
end
end
end
def subscribeduser_params
params.require(:subscribeduser).permit(:email)
end
end
這是Subscribeduser形式
<%= form_for(subscribeduser,:html => {:id => 'signup-form' }) do |f| %>
<div class="field">
<%= f.text_field :email, :name =>"email", :id => "signup-form", "placeholder" => "Email Address" %>
</div>
<div class="actions">
<%= f.submit "Sign Up!" %>
</div>
<% end %>
閱讀,請發表您的看法,以及而params您得到的控制器在創建對象 –
上面清清楚楚地寫着:subscribeduser參數是缺少這樣的東西是不對您的形式 –
你可以看看日誌並找到打印參數的行嗎?你可以把它添加到問題? –