2016-01-17 34 views
-1

關於提交我的表單拋出錯誤parameterMissing,我看我的路線和創建是顯示註冊,我也嘗試使用new_signup中從這兩個都不似乎固定錯誤。我不明白爲什麼這不起作用,並搜索其他帖子找出它,但無濟於事。ActionController :: ParameterMissing in SignupsController#create

完全錯誤

的ActionController :: ParameterMissing在SignupsController#創建

參數是丟失或爲空值:註冊

private 
def signup_params 
    params.require(:signup).permit(:email) 
end 
end 

服務器日誌

Started POST "/signups" for 50.17.182.190 at 2016-01-17 22:06:10 +0000 
Cannot render console from 50.17.182.190! Allowed networks: 127.0.0.1, ::1, 127.0.0.0/127.255.255.255 
Processing by SignupsController#create as HTML 
Parameters: {"utf8"=>"✓", "authenticity_token"=>"qteb42ekyyISXRfxX/aJEq6msi5nywvHb/vx0aTBkhLZ61hUutdgrRGP7QK6Jd2jxEesTBANQ9FiXGTLhX7crA=="} 
Completed 400 Bad Request in 70ms 
    ActionController::ParameterMissing (param is missing or the value is empty: signup): 
    app/controllers/signups_controller.rb:18:in `signup_params' 
    app/controllers/signups_controller.rb:7:in `create' 

這裏我的表格

<%= form_for(@signup, html: { class: 'form-inline' }) do |f| %> 
     <form class="form-inline"> 
     <div class="form-group"> 
     <label class="sr-only" for="signups">Email address</label> 
      <input type="email" class="form-control" id="signups" placeholder="Enter email"> 
      </div> 
     <button type="submit" class="btn btn-primary">Sign in</button> 
    </form> 
    <% end %> 

控制器

class SignupsController < ApplicationController 
def new 
@signup = Signup.new 
end 

    def create 
    @signup = Signup.new(signup_params) 

    if @signup.save 
    redirect_to root_url, notice: "Thank you for expressing interest." 
    else 
    render action: 'new', alert: "Signup failed." 
    end 
    end 

private 
def signup_params 
    params.require(:signup).permit(:email) 
end 
end 

路線

root GET/ signups#new 
      signups POST /signups(.:format)    signups#create 
      new_signup GET /signups/new(.:format)   signups#new 
      courses GET /courses(.:format)    courses#index 
        POST /courses(.:format)    courses#create 
      new_course GET /courses/new(.:format)   courses#new 
+0

如果您發佈的實際全文這將有助於錯誤信息。 – MarsAtomic

+0

我只是發佈它。 – user3905353

+2

看起來你正在複製你的'form'標籤。 Rails的'form_for'爲你創建了一個'form'標記,但是你也在下一行有一個手動的'form'標籤:'

'。刪除這一行,以及'
',這應該解決您的問題。 另外,始終縮進!這會讓閱讀你的表格變得更容易。 – dwenzel

回答

1

你的控制器期望params[:signups][:email],但您的標記實際上並沒有提供這樣的字段中<form>提交。

您需要通過form_for使用提供給您的表單輔助出示你<input>標籤,使名各input你給form_for模型的特性相匹配。

= f.text_field :email 

這將產生正確的名稱屬性的輸入:

在這種情況下,您的電子郵件<input>應改爲name="signups[email]"

+0

試過,這是行不通的。仍然拋出錯誤。 – user3905353

+0

這種形式是一種引導形式 - 我應該使用別的東西。 – user3905353

相關問題