2016-01-17 31 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

相关问题