title: Rails 4: How do I handle a submitted form where nothing was selected?
body: <p>Sorry if the title is a little confusing. I have a form for an <code>Item</code> with the field <code>name</code>. There's a text field where the user can input a name and submit it. But if the user doesn't type in anything and hits submit, Rails gives me a <code>param not found: item</code> error, and I'm not sure who to get around this. </p>
  
  <p>items_controller.rb</p>
  
  <pre><code>def new
    @item = Item.new()
  
    respond_to do |format|
      format.html
      format.json { render json: @item }
    end
  end
  
  def create
    @item = Item.new(item_params)
  
    respond_to do |format|
      if @item.save
        format.html { redirect_to items_path }
        format.json { render json: @item, status: :created, location: @item }
      else
        format.html { render action: 'new', :notice =&gt; "Input a name." }
        format.json { render json: @item.errors, status: :unprocessable_entity }
      end
    end
  end
  
  private
  
  def item_params
    params.require(:item).permit(:name)
  end
  </code></pre>
  
  <p>app/views/items/new.html.haml</p>
  
  <pre><code>= form_for @item do |f|
    = f.label :name
    = f.text_field :name
    = f.submit "Submit"
  </code></pre>
  
  <p>The params.require(:item) part is what is causing the error. What the convention for handling the error when params[:item] isn't present? </p>