0

ajaxを介して新しいアイテムを作成するカスタムの再注文アクションが機能していました。サイトの他の部分に変更を加えた後、New アクションが機能しません。

ページに移動するとcategories/reorder、またはcategories/newページが適切に読み込まれますが、行をコメントアウトした場合のみです@category = Category.new()

@category = Category.new()@category = Category.new(:parent_id => params[:parent_id])、またはを設定しようとするとすぐに、次@category = Category.newのエラー メッセージが表示されます。

No route matches {:action=>"edit", :controller=>"categories", :id=>#<Category _id: 515ee18c10188f64fb000001, created_at: nil, updated_at: nil, deleted_at: nil, ancestry: nil, user_id: nil, name: nil, description: nil, image: nil, lock: nil, _slugs: []>}

なんらかのエントリでこのエラーが発生した場合に備えて、データベースを削除しましたが、再度ログインしてもこのメッセージが表示されます。

私のルートファイルは次のとおりです。

  match '/auth/:provider/callback' => 'sessions#create'
  match '/auth/failure' => 'sessions#failure'
  match '/signout' => 'sessions#destroy', :as => :signout
  match '/signin' => 'sessions#new', :as => :signin

  match "reorder/symbols" => "categories#reorder", :via => :get, :as => :reorder_symbols
  resources :pages do
    resources :blocks do
      collection { post :sort }
    end
  end


  get 'symbols/:id/search/', to: 'categories#search', as: :sift_meanings

  get "logout" => "sessions#destroy", :as => "logout"
  get "login" => "sessions#new", :as => "login"
  get "signup" => "users#new", :as => "signup"
  resources :users
  resources :sessions
  match "meanings/:id/delete" => "meanings#destroy", :via => :get, as: :delete_meaning

  match "symbols/gallery/:id" => "categories#gallery", :via => :get
  resources :symbols, :as => :categories, :controller => :categories do
    resources :meanings
    collection {post :sort}
  end

  root :to => 'categories#index'

コントローラ ファイル:

class CategoriesController < ApplicationController
  helper :lego
  helper :meanings

  def index
    @categories = Category.all
    if params[:id]
      @categories = Category.find(params[:id])                      #if params[:id]
      @categories = @categories.subtree.arrange(:order => 'name')
    elsif params[:view] == "alpha"
      @alphabet   = Category.all.group_by{|c| c.name[0]}
      @see_kids   = false
      @categories = @categories.sort(:name => "ASC")                            if !params[:letter]
      @categories = @categories.where(name: eval("/^#{params[:letter]}/i")).sort(:name => "ASC")     if params[:letter]
    else
      # @categories = Category.all
      @categories = @categories.arrange(:order => 'name')               #if params[:view] != "list"
    end



    respond_to do |format|
      format.html # index.html.erb
      format.js
      format.json { render json: @categories }
    end
  end

  def reorder
    if Rails.env != "production" && !request.xhr?
      flash[:info] = "Currently in #{Rails.env} mode."
    end
    @categories = Category.arrange(:order => 'name')
    # @category = Category.new
    @next = Category.count
    respond_to do |format|
      format.html # index.html.erb
      format.js
      format.json { render json: @categories }
    end
  end

  def sort
    params[:category].each do |id, attr|
      thisCat = params[:category][id]
      @category = Category.where(:_id => id).first
      if thisCat.nil? || thisCat == 'null'
        @category.parent_id = nil
      else
        @category.parent_id = thisCat.to_s
      end
      @category.save
    end
  end

  def gallery
    @categories = Category.arrange(:order => 'name')
    @category = Category.find(params[:id])
    @siblings = Category.siblings_of(params[:id])
    respond_to do |format|
      format.html # index.html.erb
      format.js
      format.json { render json: @category }
    end
  end

   def show
     @categories = Category.arrange(:order => 'name')
     @category   = Category.find(params[:id])
     @updater    = User.find(@category.user) || nil
     @siblings   = Category.siblings_of(params[:id])
     @meanings   = @category.meanings #Meaning.where(:category_id => params[:id])
     @belief_list    = []
     @culture_list   = []
     @contributors   = []
     @connotations   = []
     for meaning in @meanings
       for belief in meaning.beliefs
         @belief_list << belief 
       end
       for culture in meaning.cultures
         @culture_list << culture
       end
       @connotations << meaning.connotation
       @contributors << meaning.user
     end
     @beliefs      = @belief_list.uniq
     @cultures     = @culture_list.uniq
     @contributors = @contributors.uniq
     @connotations = @connotations.uniq

     respond_to do |format|
       format.html # show.html.erb
       format.js
       format.json { render json: @category }
     end
   end

  def search
    @categories = Category.arrange(:order => 'name')
    @category = Category.find(params[:id])

    @meanings = @category.meanings
    @meanings = @meanings.where(:beliefs => params[:beliefs])         if params[:beliefs]
    @meanings = @meanings.where(:cultures => params[:cultures])       if params[:cultures]
    @meanings = @meanings.where(:connotation => params[:connotation]) if params[:connotation]
    @meanings = @meanings.where(:user => params[:user])               if params[:user]    
  end


  # GET /categories/new
  # GET /categories/new.json
  def new
    @category = Category.new(:parent_id => params[:parent_id])
    # @category.photo.build
    respond_to do |format|
      format.html # new.html.erb
      format.js
      format.json { render json: @category }
    end
  end

  # GET /categories/1/edit
  def edit
    @category = Category.find(params[:id])
  end

  # POST /categories
  # POST /categories.json
  def create
    @category = Category.new(params[:category])
    @category.user = current_user
    @categories = Category.arrange(:order => :created_at)
    if @category.save
      flash[:success] = "<h4><i class=icon-ok></i> '#{@category.name}' was successfully created.</h4>"
    end
    respond_to do |format|
      if @category.save
        format.html { redirect_to @categories, notice: 'Category was successfully created.' }
        format.js
        format.json { render json: @categories, status: :created, location: @category }
      else
        format.html { render action: "new" }
        format.js 
        format.json { render json: @category.errors, status: :unprocessable_entity }
      end
    end
  end

  # PUT /categories/1
  # PUT /categories/1.json
  def update
    @category = Category.find(params[:id])
    @category.user = current_user
    flash[:success] = "<h4><i class=icon-ok></i> #{@category.name} was successfully updated.</h4>"
    respond_to do |format|
      if @category.update_attributes(params[:category])
        format.html { redirect_to @category}
        format.js
        format.json { head :no_content }
      else
        format.html { render action: "edit", error: "Unable to update '#{@category.name}'", status: :unprocessable_entity }
        format.json { render json: @category.errors, status: :unprocessable_entity }
      end
    end
  end

  # DELETE /categories/1
  # DELETE /categories/1.json
  def destroy
    @category = Category.find(params[:id])
    @category.destroy
    flash[:alert] = "<h4><i class=icon-warning-sign></i> Warning. You have deleted the category '#{@category.name}'.</h4>".html_safe


    respond_to do |format|
      format.html { redirect_to categories_url }
      format.json { head :no_content }
      format.js 
    end
  end

  def has_sidebar?
    self.has_children?
  end
private

end

他に注意すべき唯一のことは、Twitter Bootstrap 変数が正しく設定されていないため、以前の動作バージョンに戻すときにサーバーを再起動する必要があることです。しかし、それがこれに影響を与えるべきではないと思います。

4

1 に答える 1

0

スタック トレースをたどると、エラーの場所が表示されます。これは への呼び出しを追加した場合にのみ発生するとおっしゃっていたので、編集リンクを作成する@category = Category.newために を使用しているためだとしか思えません。@categoryただし@category、新しいオブジェクトであるため、エラーが発生します。編集リンクがあるビュー ファイルを調べてみてください。

于 2013-04-05T15:30:23.147 に答える