Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby-on-rails-4/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Forms ArgumentError对于部分形式,形式中的第一个参数不能包含nil或为空_Forms_Ruby On Rails 4_Modal Dialog - Fatal编程技术网

Forms ArgumentError对于部分形式,形式中的第一个参数不能包含nil或为空

Forms ArgumentError对于部分形式,形式中的第一个参数不能包含nil或为空,forms,ruby-on-rails-4,modal-dialog,Forms,Ruby On Rails 4,Modal Dialog,我的注册表单工作正常,但一旦我将注册从移动到部分\u signup.html.erb中,它就给了我一个错误“表单中的第一个参数不能包含nil或为空” 我想让来自的用户注册通过主页的模式,而不是重定向到new.html.erb 静态页面/home.html.erb <% else %> <button type="button" class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal"&

我的注册表单工作正常,但一旦我将注册从移动到部分
\u signup.html.erb
中,它就给了我一个错误“表单中的第一个参数不能包含nil或为空”

我想让来自的用户注册通过主页的模式,而不是重定向到
new.html.erb

静态页面/home.html.erb

<% else %>
  <button type="button" class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal">
    Sign up with email
  </button>
  <div class="modal fade">
    <div class="modal-dialog">
      <div class="modal-content">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
          <h4 class="modal-title">Sign up</h4>
        </div>
        <div class="modal-body">
          <%= render partial: 'users/signup', locals: {user: @user} %>
        </div>
      </div>
    </div>
  </div>
<% end %>
<div class="row">
  <div class="col-md-6 col-md-offset-3">
    <%= form_for(@user) do |f| %>
    <form id="SignupForm">
      <%= render 'shared/error_messages' %>
      <fieldset>
        <legend>Fill in your info</legend>

        <%= f.label :username %>
        <%= f.text_field :username, class: 'form-control' %>

        <%= f.label :name %>
        <%= f.text_field :name, class: 'form-control' %>

        <%= f.label :email %>
        <%= f.email_field :email, class: 'form-control' %>

        <%= f.label :password %>
        <%= f.password_field :password, class: 'form-control' %>

        <%= f.label :password_confirmation %>
        <%= f.password_field :password_confirmation, class: 'form-control' %>
        <fieldset>
        </fieldset>
        <legend>Languages</legend>
        <label for="Gender">Select gender</label>
        <%= f.select :sex, options_for_select([['Select Gender', ''],['Male','1'],['Female','2']], "#{@user.sex}") %>

        <label for="Country">Fill in your location</label>
        <%= f.country_select :country_code, { priority_countries: ["GB", "US"] }, class: 'required-field', required: true %>

        <%= f.submit "Create my account", class: "btn btn-primary" %>
        <% end %>
      </fieldset>
    </form> 
  </div>
</div>
class UsersController < ApplicationController
    respond_to :html, :js
   before_action :logged_in_user, only: [:index, :show, :edit, :update, :destroy]
    before_action :correct_user,   only: [:edit, :update]
    before_action :admin_user,     only: :destroy

  def index
    @users = User.paginate(page: params[:page])
  end

 def show
    @user = User.find(params[:id])
    @page_name = "user_page"
  end

  def new
    @user = User.new
  end

  def signup
    @user = User.new
  end

  def create
    @user = User.new(user_params)
    if @user.save
         @user.send_activation_email
      flash[:info] = "Please check your email to activate your account."
      redirect_to root_url
    else
        render 'new'
    end
  end

  def edit
   @user = User.find(params[:id])
  end
<div class="modal-body">
  <%= render partial: 'users/signup', locals: {user: @user} %>
</div>
<div class="row">
  <div class="col-md-6 col-md-offset-3">
    <%= form_for(user) do |f| %>
    <form id="SignupForm">
      <%= render 'shared/error_messages' %>
      <fieldset>
        <legend>Fill in your info</legend>

        <%= f.label :username %>
        <%= f.text_field :username, class: 'form-control' %>

        <%= f.label :name %>
        <%= f.text_field :name, class: 'form-control' %>

        <%= f.label :email %>
        <%= f.email_field :email, class: 'form-control' %>

        <%= f.label :password %>
        <%= f.password_field :password, class: 'form-control' %>

        <%= f.label :password_confirmation %>
        <%= f.password_field :password_confirmation, class: 'form-control' %>
        <fieldset>
        </fieldset>
        <legend>Languages</legend>
        <label for="Gender">Select gender</label>
        <%= f.select :sex, options_for_select([['Select Gender', ''],['Male','1'],['Female','2']], "#{user.sex}") %>

        <label for="Country">Fill in your location</label>
        <%= f.country_select :country_code, { priority_countries: ["GB", "US"] }, class: 'required-field', required: true %>

        <%= f.submit "Create my account", class: "btn btn-primary" %>
        <% end %>
      </fieldset>
    </form>
  </div>
</div>

您无权访问部分中的实例变量
@user
。必须将其作为局部变量传递:

静态页面/home.html.erb

<% else %>
  <button type="button" class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal">
    Sign up with email
  </button>
  <div class="modal fade">
    <div class="modal-dialog">
      <div class="modal-content">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
          <h4 class="modal-title">Sign up</h4>
        </div>
        <div class="modal-body">
          <%= render partial: 'users/signup', locals: {user: @user} %>
        </div>
      </div>
    </div>
  </div>
<% end %>
<div class="row">
  <div class="col-md-6 col-md-offset-3">
    <%= form_for(@user) do |f| %>
    <form id="SignupForm">
      <%= render 'shared/error_messages' %>
      <fieldset>
        <legend>Fill in your info</legend>

        <%= f.label :username %>
        <%= f.text_field :username, class: 'form-control' %>

        <%= f.label :name %>
        <%= f.text_field :name, class: 'form-control' %>

        <%= f.label :email %>
        <%= f.email_field :email, class: 'form-control' %>

        <%= f.label :password %>
        <%= f.password_field :password, class: 'form-control' %>

        <%= f.label :password_confirmation %>
        <%= f.password_field :password_confirmation, class: 'form-control' %>
        <fieldset>
        </fieldset>
        <legend>Languages</legend>
        <label for="Gender">Select gender</label>
        <%= f.select :sex, options_for_select([['Select Gender', ''],['Male','1'],['Female','2']], "#{@user.sex}") %>

        <label for="Country">Fill in your location</label>
        <%= f.country_select :country_code, { priority_countries: ["GB", "US"] }, class: 'required-field', required: true %>

        <%= f.submit "Create my account", class: "btn btn-primary" %>
        <% end %>
      </fieldset>
    </form> 
  </div>
</div>
class UsersController < ApplicationController
    respond_to :html, :js
   before_action :logged_in_user, only: [:index, :show, :edit, :update, :destroy]
    before_action :correct_user,   only: [:edit, :update]
    before_action :admin_user,     only: :destroy

  def index
    @users = User.paginate(page: params[:page])
  end

 def show
    @user = User.find(params[:id])
    @page_name = "user_page"
  end

  def new
    @user = User.new
  end

  def signup
    @user = User.new
  end

  def create
    @user = User.new(user_params)
    if @user.save
         @user.send_activation_email
      flash[:info] = "Please check your email to activate your account."
      redirect_to root_url
    else
        render 'new'
    end
  end

  def edit
   @user = User.find(params[:id])
  end
<div class="modal-body">
  <%= render partial: 'users/signup', locals: {user: @user} %>
</div>
<div class="row">
  <div class="col-md-6 col-md-offset-3">
    <%= form_for(user) do |f| %>
    <form id="SignupForm">
      <%= render 'shared/error_messages' %>
      <fieldset>
        <legend>Fill in your info</legend>

        <%= f.label :username %>
        <%= f.text_field :username, class: 'form-control' %>

        <%= f.label :name %>
        <%= f.text_field :name, class: 'form-control' %>

        <%= f.label :email %>
        <%= f.email_field :email, class: 'form-control' %>

        <%= f.label :password %>
        <%= f.password_field :password, class: 'form-control' %>

        <%= f.label :password_confirmation %>
        <%= f.password_field :password_confirmation, class: 'form-control' %>
        <fieldset>
        </fieldset>
        <legend>Languages</legend>
        <label for="Gender">Select gender</label>
        <%= f.select :sex, options_for_select([['Select Gender', ''],['Male','1'],['Female','2']], "#{user.sex}") %>

        <label for="Country">Fill in your location</label>
        <%= f.country_select :country_code, { priority_countries: ["GB", "US"] }, class: 'required-field', required: true %>

        <%= f.submit "Create my account", class: "btn btn-primary" %>
        <% end %>
      </fieldset>
    </form>
  </div>
</div>

谢谢,这是我的想法,但我不确定如何改变@user的范围。我会投你一票,但我的名声似乎不够好。谢谢,请接受我的回答。“接受”按钮/链接位于上下投票链接的正下方。任何提出问题的人都可以接受答案。这是获得更多声誉的第一步。