Rails - UsersController中的ArgumentError #create - 参数太少

Kev*_*161 2 authentication arguments ruby-on-rails devise

这可能是非常基本的,但我似乎无法弄明白.

基本上,当我尝试使用表单创建新用户,并且用户详细信息已经存在且不唯一时,我收到以下错误:

ArgumentError in UsersController#create

too few arguments

Application Trace | Framework Trace | Full Trace
app/controllers/users_controller.rb:61:in `format'
app/controllers/users_controller.rb:61:in `create'
Run Code Online (Sandbox Code Playgroud)

这是我create在我的行动user_controller.rb:

  # POST /users
  # POST /users.xml
  def create
      @user = User.new(params[:user])

        if @user.save
          flash[:notice] = 'User successfully created' and redirect_to :action=>"index"
        else
          format.html { render :action => "new" }
          format.xml  { render :xml => @user.errors, :status => :unprocessable_entity }
        end
      end
    end
Run Code Online (Sandbox Code Playgroud)

这是我的 user.rb

class User < ActiveRecord::Base
  # Include default devise modules. Others available are:
  # :token_authenticatable, :confirmable,
  # :lockable, :timeoutable and :omniauthable
  devise :database_authenticatable,
         :recoverable, :rememberable, :trackable, :validatable

  # Setup accessible (or protected) attributes for your model
  attr_accessible :email, :username, :password, :password_confirmation, :remember_me

  validates :email, :username, :presence => true, :uniqueness => true
end
Run Code Online (Sandbox Code Playgroud)

这也是我的形式:

<%= simple_form_for(@user) do |f| %>
  <div class="field">
    <%= f.input :username %>
  </div>
  <div class="field">
    <%= f.input :email %>
  </div>
    <div class="field">
      <%= f.input :password %>
    </div>
    <div class="field">
      <%= f.input :password_confirmation %>
    </div>
  <div class="actions">
    <%= f.button :submit %>
  </div>
<% end %>
Run Code Online (Sandbox Code Playgroud)

Dav*_*ton 6

什么是format在这种情况下?

没有respond_to阻挡,把它放回去!你引用了其他一些format.