mardi 30 juin 2015

Can't Edit Item Error NoMethodError in Items#edit

I have an Item Model. Its for a retail store.

When im on an item view. Lets say for item id 11. Then i click on edit button. I receive the following error

Anyone have any clues? Any help would be greatly appreciated.

NoMethodError in Items#edit
undefined method `errors' for nil:NilClas
<% if @user.errors.any? %>
  <div id="error_explanation">
    <div class="alert alert-danger">
      The form contains <%= pluralize(@user.errors.count, "error") %>.
    </div>
    <ul>

Below is where my edit button is in Item View

<!-- right column -->
  <div class="col-lg-6 col-md-6 col-sm-5">
      <div class = "itemtitle"><%= @item.title %> </div> 
      <div class = "price">$<%= @item.price %> </div> 
      <%= link_to "Edit Items", edit_item_path(@item) %>
      <div class="productFilter productFilterLook2">
          <div class="filterBox">
              <select>
                  <option value="strawberries" selected>Quantity</option>
              </select>
          </div>

Here is my Items controller.

class ItemsController < ApplicationController

  def index
    @items = Item.paginate(page: params[:page])
  end

  def new
    @item = Item.new
  end

  def edit
    @item = Item.find(params[:id])
  end

  def show
    @item = Item.find(params[:id])
  end

  def update
    if @item.update(pin_params)
      redirect_to @item, notice: 'Item was successfully updated.'
    else
      render action: 'edit'
    end
  end

  def create
    @item = current_user.items.build(item_params)
    if @item.save
      redirect_to @item
      flash[:success] = "You have created a new item"
    else
      flash[:danger] = "Your item didn't save"
      render "new"
    end
  end

  def destroy
    @item.destroy
    respond_to do |format|
      format.html { redirect_to items_url, notice: 'Item was successfully deleted' }
      format.json { head :no_content }
    end
  end

  private

    def item_params
      params.require(:item).permit(:title, :price, :description, :image)
    end

end

Aucun commentaire:

Enregistrer un commentaire